SimdSet

Set implementation that is well suited for small sets and simple items.

Uses SSE instructions to compare multiple elements simultaneously, but has linear time complexity. Use this container when you need to

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.

  1. struct SimdSet(T)
    version(D_InlineAsm_X86_64)
    struct SimdSet (
    T
    ) if (
    T.sizeof == 1 ||
    T.sizeof == 2
    ||
    T.sizeof == 4
    ||
    T.sizeof == 8
    ) {}
  2. struct SimdSet(T)

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Functions

contains
bool contains(T item)
insert
bool insert(T item)

Inserts the given item into the set.

length
size_t length()
remove
bool remove(T item)

Removes the given item from the set.

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();

Meta