sparse 1.0.2

Sparse sets, compatible with BetterC, @nogc, and nothrow.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

SparseD

An incredibly simple sparse set implemented in D with static arrays. Compatible with BetterC, @nogc, and nothrow.

Currently, the whole implementation is nothrow @nogc pure @safe, although this could change in the future.

Documentation is provided in the library's source code. Make sure to also read a function's preconditions where applicable.

Example

import sparse;
import std.stdio: writefln;

void main(){
	SparseSet!(string, 128, 64) mySet; //Can store up to 64 strings, with unique IDs 0–127.
	
	mySet.add(12, "Twelve"); //O(1) element insertion
	mySet.add(7, "Seven");
	mySet.add(49, "Forty-nine");
	foreach(ref element; mySet.denseElements){ //Same speed as a foreach over an array
		writefln("%d: %s", element.ind, element.value);
		//12: Twelve
		//7: Seven
		//49: Forty-nine
		element.value ~= "!!";
	}
	mySet.remove(12); //O(1) element removal
	foreach(element; mySet.denseElementsConst){ //Still the speed as a foreach over an array!
		writefln("%d: %s", element.ind, element.value);
		//49: Forty-nine!!
		//7: Seven!!
	}
	if(auto valuePtr = 49 in mySet){ //O(1) element look-up (can also be done with `.has()` and then `.get()`/`.read()`)
		assert(*valuePtr == "Forty-nine!!");
	}
	mySet.clear(); //O(1) clearing
}
Authors:
  • Aya Partridge
Dependencies:
none
Versions:
1.0.2 2024-May-03
1.0.1 2024-Apr-28
1.0.0 2024-Apr-25
~main 2024-May-03
Show all 4 versions
Download Stats:
  • 1 downloads today

  • 1 downloads this week

  • 2 downloads this month

  • 2 downloads total

Score:
0.3
Short URL:
sparse.dub.pm