FastSet

almost same boolint, except key range is stricted

Constructors

this
this(size_t n)

make set for [0, 1, ..., n-1]

Members

Functions

lowerBound
Range lowerBound(ptrdiff_t x)

return range that contain less than x

next
ptrdiff_t next(ptrdiff_t x)

return minimum element that isn't less than x

opIndex
Range opIndex()
prev
ptrdiff_t prev(ptrdiff_t x)

return maximum element that isn't greater than x

upperBound
Range upperBound(ptrdiff_t x)

return range that contain greater than x

Structs

Range
struct Range

bidirectional range

Examples

1 import std.algorithm : equal, map;
2 import std.range : iota;
3 auto fs = FastSet(10);
4 fs.insert(1);
5 fs.insert(5);
6 fs.insert(6);
7 fs.remove(5);
8 fs.insert(4);
9 // [1, 4, 6]
10 assert(1 in fs);
11 assert(2 !in fs);
12 assert(5 !in fs);
13 assert(6 in fs);
14 assert(equal([1, 4, 6], fs[]));
15 assert(equal(
16     iota(8).map!(i => fs.next(i)),
17     [1, 1, 4, 4, 4, 6, 6, 10]
18 ));
19 assert(equal(
20     iota(8).map!(i => fs.prev(i)),
21     [-1, 1, 1, 1, 4, 4, 6, 6]
22 ));
23 assert(equal([1], fs.lowerBound(4)));
24 assert(equal([1, 4], fs.lowerBound(5)));
25 assert(equal([1, 4, 6], fs.upperBound(0)));
26 assert(equal([4, 6], fs.upperBound(1)));

Meta