2012/10/10 Ramon Smits <[email protected]> > > Maybe a little bit off-topic... > > How should I see an OrderedSet? A set has unique items which is the basic > requirement of a set. A list has the basic requirement of having ordering > but does not prevent a unique item collection. When I insert 1,2,3,4,2 in > the OrderedSet then what will I get when I read this collection? 1,2,3,4 or > 1,3,4,2? I think hit is pretty flawed by design. >
>From a mathematical viewpoint, speaking of ordering in a set would be an abomination I guess. But then comes reality and tells us that it might still be useful. :) The implementation follows the same principle as Java's LinkedHashSet: http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashSet.html Behavior when adding elements already in the set is well-defined, and in my view reasonably logical: Adding "2" to a set where "2" is already a member results in no actual insertion - therefore the existing "2" will keep its original position. UnionWith(), IntersectWith(), etc. also follows this principle: elements remaining in the set keep their relative positions, elements added by the operation are positioned after all existing elements, in the order they are received from the "other" enumeration. Hmm, personally I wouldn't mind renaming it to LinkedHashSet to make it perhaps less easily confused with SortedSet. > How would you use an orderedset in NHibernate? Would you use this for a > bag, set and/or list? > I gather it's basically only there to support the order-by attribute for <set>, to preserve an ordering generated in the database. /Oskar
