containers.simdset
SIMD-accelerated Set
-
Declaration
struct
SimdSet
(T, Allocator = Mallocator) if (T.sizeof == 1 || T.sizeof == 2 || T.sizeof == 4 || T.sizeof == 8);Set implementation that is well suited for small sets and simple items.
Discussion
Uses SSE instructions to compare multiple elements simultaneously, but has linear time complexity.
Note: Only works on x86_64. Does NOT add GC ranges. Do not store pointers in this container unless they are also stored somewhere else.
Parameters
T
the element type
Allocator
the allocator to use. Defaults to
Mallocator
.Examples
import std.string : format; void testSimdSet(T)() { SimdSet!T set; assert(set.insert(1)); assert(set.length == 1); assert(set.contains(1)); assert(!set.insert(1)); set.insert(0); set.insert(20); assert(set.contains(1)); assert(set.contains(0)); assert(!set.contains(10)); assert(!set.contains(50)); assert(set.contains(20)); foreach (T i; 28 .. 127) set.insert(i); foreach (T i; 28 .. 127) assert(set.contains(i), "%d".format(i)); foreach (T i; 28 .. 127) assert(set.remove(i)); assert(set.length == 3, "%d".format(set.length)); assert(set.contains(0)); assert(set.contains(1)); assert(set.contains(20)); assert(!set.contains(28)); } testSimdSet!ubyte(); testSimdSet!ushort(); testSimdSet!uint(); testSimdSet!ulong(); testSimdSet!byte(); testSimdSet!short(); testSimdSet!int(); testSimdSet!long();
-
Declaration
this();
No default construction if an allocator must be provided.
-
Declaration
this(Allocator
allocator
);Use the given
for allocations.allocator
-
Declaration
const pure nothrow @nogc @trusted bool
contains
(Titem
);
const pure nothrow @nogc @safe boolopBinaryRight
(string op)(Titem
) if (op == "in");Parameters
T
item
the
item
to checkReturn Value
true
if the setcontains
the givenitem
-
Declaration
bool
insert
(Titem
);
boolopOpAssign
(string op)(Titem
) if (op == "~");
aliasinsertAnywhere
= insert;
aliasput
= insert;Inserts the given
item
into the set.Parameters
T
item
the
item
toinsert
Return Value
true
if theitem
was inserted orfalse
if it was already present -
Declaration
bool
remove
(Titem
);Removes the given
item
from the set.Parameters
T
item
the time to
remove
Return Value
true
if theitem
was removed,false
if it was not present -
Declaration
auto
opSlice
(this This)();Slice operator
-
Declaration
const pure nothrow @nogc @property size_t
length
();Return Value
the number of items in the set