On 02/09/12 22:42, SomeDude wrote:
On Sunday, 2 September 2012 at 15:09:50 UTC, deadalnix wrote:
Le 02/09/2012 16:51, Jacob Carlborg a écrit :
I really don't like the name "handful". What would be the difference
compared to a regular set container? To me it sounds like we should have
a standard set container in Phobos, std.container.set.
+1, and we are back to the allocator design.
+2 on the basis of typical "real world" (if I may says so) usage. It
calls for a set container, both mutable and immutable.
For a "handful" of values (say 5 or less), I'm not even sure the O(1)
method is faster than the O(n) one.
As for the intervals, I suppose one would have to define open intervals,
because I think they would be much more useful than closed ones when the
intervals are contiguous (in particular with floats/doubles).
One must be able to translate x0 <= x < x1 in intervals else they are
practically useless for anything else than integers and other discrete
values.
But practically everything on a computer uses discrete values. Floating
point numbers always do, for example; they are *not* mathematical real
numbers with infinite precision.
For floats and doubles, any non-empty interval can be expressed using
closed intervals.
Use the nextUp() and nextDown() to convert between open and closed
intervals.
[ x .. y ] == ( nextDown(x) .. nextUp(y) )
( x .. y ) == [ nextUp(x) .. nextDown(y) ]
In general:
Fully closed interval: cannot express an empty interval.
Fully open interval: cannot express a maximum-sized interval. Empty
intervals can be expressed but not uniquely.
Half-open: not closed under negation.
Either of the first two are reasonable choices for arithmetic
applications. The third is broken for anything that allows negative values.