L
Lasse Reichstein Nielsen
Christian said:you could for example without to large overhead do a set with a order
by simply holding 2 arrays in the class.. one for the hashbuckets and
one for the order ...
No, that would require a significant overhead whenever you update
the contents of the set. The order needs updating.
Keeping an ordered array in order during insertion requires linear
time per insert - for inserting in the middle of the array.
Other way would be to introduce a next pointer in the Entry objects
that points to the next Object in order
Keeping an ordered linked list in order during insertion requires
linear time per insert - for finding the position to insert at.
there is really no reason what so ever for an ordered set to perform
asymptotically worse then the normal hashset..
For insertions, yes there is. If not, you could do sorting in linear
time by inserting the elements into a "ordered hash set", and extracting
them again. That's theoretically impossible, as comparison based sorting
requires at least O(n*log(n)) comparisons.
Actually Java already has such a Set that does this called LinkedHashSet.
That set retains insertion order, not any logical order.
/L