// Publics public void Add(T value) { // Get potential lists pool IEnumerable <Trait <T> > activeTraits = GetTraits(value); var potentials = Utility.Intersect(GetMinListsByTrait(activeTraits)); if (potentials.Count == 0) { potentials = GetListsWithMostMinTraits(activeTraits); } // Choose a list and add element TraitList <T> chosenList = potentials.Random(); chosenList.Add(new TraitElement <T>(value, activeTraits)); // Update minLists foreach (var trait in activeTraits) { if (_minListsByTrait[trait].Remove(chosenList) && _minListsByTrait[trait].Count == 0) { _minListsByTrait[trait] = GetMinLists(trait, chosenList.TraitCount(trait)); } } }
// Constructors public TraitEqualizer(int listsCount, Trait <T>[] traits) { _traits = traits; _lists = new TraitList <T> [listsCount]; for (int i = 0; i < _lists.Length; i++) { _lists[i] = new TraitList <T>(_traits); } _minListsByTrait = new Dictionary <Trait <T>, List <TraitList <T> > >(); foreach (var trait in _traits) { _minListsByTrait[trait] = _lists.ToList(); } }