예제 #1
0
        static void SetDemo()
        {
            //Set:key-List<value>  场景:去重、共同好友、共同关注
            using (ExSet service = new ExSet())
            {
                service.KeyFulsh();
                // ex去重,统计用户ip记录
                {
                    service.SetAdd <string>("user1", "36.235.120.63");
                    service.SetAdd <string>("user1", "36.235.120.63");
                    service.SetAdd <string>("user1", "36.225.120.63");
                    service.SetAdd <string>("user1", "36.235.120.63");
                    service.SetAdd <string>("user1", "36.235.111.63");
                    service.SetAdd <string>("user1", "36.235.120.63");
                    service.SetAdd <string>("user1", "33.235.120.63");
                    service.SetAdd <string>("user1", "36.235.120.66");
                    service.SetAdd <string>("user1", "36.235.120.66");
                }
                Console.WriteLine("IP Count:" + service.SetLength("user1"));
                service.SetAdd <string>("A", "1");
                service.SetAdd <string>("A", "2");
                service.SetAdd <string>("A", "3");
                service.SetAdd <string>("A", "4");
                service.SetAdd <string>("A", "5");

                service.SetAdd <string>("B", "3");
                service.SetAdd <string>("B", "4");
                service.SetAdd <string>("B", "5");
                service.SetAdd <string>("B", "6");
                service.SetAdd <string>("B", "7");
                Console.WriteLine("");
                Console.WriteLine("[并集]:");
                var AB_Union = service.SetCombine(SetOperation.Union, "A", "B");
                foreach (string str in AB_Union)
                {
                    Console.Write(str + " ");
                }
                Console.WriteLine("");
                Console.WriteLine("[交集] :");
                var AB_Intersect = service.SetCombine(SetOperation.Intersect, "A", "B");
                foreach (string str in AB_Intersect)
                {
                    Console.Write(str + " ");
                }
                Console.WriteLine("");
                Console.WriteLine("AB[差集]:");
                var AB_Difference = service.SetCombine(SetOperation.Difference, "A", "B");
                foreach (string str in AB_Difference)
                {
                    Console.Write(str + " ");
                }
                Console.WriteLine("");
                Console.WriteLine("BA[差集]:");
                var BA_Difference = service.SetCombine(SetOperation.Difference, "B", "A");
                foreach (string str in BA_Difference)
                {
                    Console.Write(str + " ");
                }
            }
        }
 public void Add(Statement pos, ExSet existentials)
 {
   //System.Console.WriteLine("Adding existentials at position:{0}:{1}", pos, pos.GetHashCode());
   //if (pos != null) System.Console.WriteLine("  (line: {0}, column {1})", pos.SourceContext.StartLine, pos.SourceContext.StartColumn);
   //existentials.printAll();
   if (pos == null) return;
   //if (pos.SourceContext == null) return;
   if (pos.UniqueKey == 0) return;
   if (!table.ContainsKey(pos.UniqueKey))
       table.Add(pos.UniqueKey, existentials);
 }