// From an anagram point of view, a word is just a bag of // characters. So an anagram class is represented as TreeBag<char> // which permits fast equality comparison -- we shall use them as // elements of hash sets or keys in hash maps. public static TreeBag<char> AnagramClass(String s) { TreeBag<char> anagram = new TreeBag<char>(SCG.Comparer<char>.Default, EqualityComparer<char>.Default); foreach (char c in s) anagram.Add(c); return anagram; }
// From an anagram point of view, a word is just a bag of // characters. So an anagram class is represented as TreeBag<char> // which permits fast equality comparison -- we shall use them as // elements of hash sets or keys in hash maps. public static TreeBag <char> AnagramClass(String s) { TreeBag <char> anagram = new TreeBag <char>(SCG.Comparer <char> .Default, EqualityComparer <char> .Default); foreach (char c in s) { anagram.Add(c); } return(anagram); }
public static TreeBag <char> TreeBag(String s) { TreeBag <char> anagram = new TreeBag <char>(); foreach (char c in s) { anagram.Add(c); } return(anagram); }
public TreeBag <T> CopyToTreeBag <T>(ICollection <T> lst) { TreeBag <T> lstCopy = new TreeBag <T>(); foreach (var item in lst) { lstCopy.Add((T)item); } return(lstCopy); }
// From an anagram point of view, a word is just a bag of // characters. So an anagram class is represented as TreeBag<char> // which permits fast equality comparison -- we shall use them as // elements of hash sets or keys in hash maps. // From an anagram point of view, a word is just a bag of // characters. So an anagram class is represented as HashBag<char> // which permits fast equality comparison -- we shall use them as // elements of hash sets or keys in hash maps. static TreeBag <char> AnagramClass(string s) { var anagram = new TreeBag <char>(); foreach (char c in s) { anagram.Add(c); } return(anagram); }
public void TestTreeMapSpecialOperation() { var bag = new TreeBag <Order>((x1, x2) => x1.Id - x2.Id); for (var i = 0; i < 1000; i++) { bag.Add(new Order { Id = i + 1 }); } Assert.Equal(1, bag.Min.Id); Assert.Equal(1000, bag.Max.Id); }
public static TreeBag<char> TreeBag(String s) { TreeBag<char> anagram = new TreeBag<char>(); foreach (char c in s) anagram.Add(c); return anagram; }
public static void Main(String[] args) { var list = new TreeBag <long>(); // Sequence generated in FindNodeRandomTest list.Add(553284); list.Add(817435); list.Remove(817435); list.Add(155203); list.Add(316201); list.Remove(316201); list.Add(145375); list.Remove(155203); list.Add(155203); list.Add(150788); list.Remove(145375); list.Add(316201); list.Add(263469); list.Add(263469); list.Add(441406); list.Add(553284); list.Remove(553284); list.Add(553284); list.Remove(150788); list.Add(769005); list.Add(263469); list.Remove(316201); list.Add(553284); list.Remove(769005); list.Add(316201); list.Remove(263469); list.Add(817435); list.Add(553284); list.Remove(316201); list.Add(150788); // list.Add(0.553284f); // list.Add(0.8174357f); // list.Remove(0.8174357f); // list.Add(0.1552035f); // list.Add(0.3162012f); // list.Remove(0.3162012f); // list.Add(0.1453752f); // list.Remove(0.1552035f); // list.Add(0.1552035f); // list.Add(0.1507881f); // list.Remove(0.1453752f); // list.Add(0.3162012f); // list.Add(0.2634694f); // list.Add(0.2634694f); // list.Add(0.4414065f); // list.Add(0.553284f); // list.Remove(0.553284f); // list.Add(0.553284f); // list.Remove(0.1507881f); // list.Add(0.7690055f); // list.Add(0.2634694f); // list.Remove(0.3162012f); // list.Add(0.553284f); // list.Remove(0.7690055f); // list.Add(0.3162012f); // list.Remove(0.2634694f); // list.Add(0.8174357f); // list.Add(0.553284f); // list.Remove(0.3162012f); // list.Add(0.1507881f); Console.WriteLine(list); Console.WriteLine(list.Count > 3); Console.WriteLine(list[0]); Console.WriteLine(list[1]); Console.WriteLine(list[2]); // Throws! // Console.WriteLine(list[0,1]); // Console.WriteLine(list[1,1]); // Console.WriteLine(list[2,1]); // Worse: Throws too! }
public static void Main(String[] args) { var list = new TreeBag<long>(); // Sequence generated in FindNodeRandomTest list.Add(553284); list.Add(817435); list.Remove(817435); list.Add(155203); list.Add(316201); list.Remove(316201); list.Add(145375); list.Remove(155203); list.Add(155203); list.Add(150788); list.Remove(145375); list.Add(316201); list.Add(263469); list.Add(263469); list.Add(441406); list.Add(553284); list.Remove(553284); list.Add(553284); list.Remove(150788); list.Add(769005); list.Add(263469); list.Remove(316201); list.Add(553284); list.Remove(769005); list.Add(316201); list.Remove(263469); list.Add(817435); list.Add(553284); list.Remove(316201); list.Add(150788); // list.Add(0.553284f); // list.Add(0.8174357f); // list.Remove(0.8174357f); // list.Add(0.1552035f); // list.Add(0.3162012f); // list.Remove(0.3162012f); // list.Add(0.1453752f); // list.Remove(0.1552035f); // list.Add(0.1552035f); // list.Add(0.1507881f); // list.Remove(0.1453752f); // list.Add(0.3162012f); // list.Add(0.2634694f); // list.Add(0.2634694f); // list.Add(0.4414065f); // list.Add(0.553284f); // list.Remove(0.553284f); // list.Add(0.553284f); // list.Remove(0.1507881f); // list.Add(0.7690055f); // list.Add(0.2634694f); // list.Remove(0.3162012f); // list.Add(0.553284f); // list.Remove(0.7690055f); // list.Add(0.3162012f); // list.Remove(0.2634694f); // list.Add(0.8174357f); // list.Add(0.553284f); // list.Remove(0.3162012f); // list.Add(0.1507881f); Console.WriteLine(list); Console.WriteLine(list.Count > 3); Console.WriteLine(list[0]); Console.WriteLine(list[1]); Console.WriteLine(list[2]); // Throws! // Console.WriteLine(list[0,1]); // Console.WriteLine(list[1,1]); // Console.WriteLine(list[2,1]); // Worse: Throws too! }