diff --git a/docs/deps.svg b/docs/deps.svg new file mode 100644 index 0000000..13c7679 --- /dev/null +++ b/docs/deps.svg @@ -0,0 +1,67 @@ + + + + + diff --git a/docs/eris.allocator.Allocator.alignment.html b/docs/eris.allocator.Allocator.alignment.html new file mode 100644 index 0000000..73fa032 --- /dev/null +++ b/docs/eris.allocator.Allocator.alignment.html @@ -0,0 +1,35 @@ + + +
+Attempts to allocate a memory block of size bytes.
If size == 0, the returned slice might have a null .ptr, but either way + it can be safely deallocated.
The allocated memory block, or null on allocation failure.
Deallocates a previously-allocated memory block.
NOTE: Unlike in std.experimental.allocator, this method does not have to return anything.
Base allocator interface.
All memory obtained with allocate must be disposed by deallocate on the same allocator instance.
NOTE: Unlike std.experimental.allocator, + we always require a deallocation procedure.
Attempts to allocate a memory block of size bytes.
Deallocates a previously-allocated memory block.
Minimum alignment of all allocated memory blocks.
C stdlib allocator using malloc and free.
Destroy and deallocate a given object/array.
Destroy and deallocate a given object/array.
Custom memory allocators and related helpers.
Based on std.experimental.allocator, +without being strictly compatible.
Destroy and deallocate a given object/array.
Allocate and construct an object of the specified type.
Make an array of the specified type.
Base allocator interface.
C stdlib allocator using malloc and free.
Static interface counterpart of Allocator.
Alignment large enough for any scalar type.
Allocate and construct an object of the specified type.
struct S { bool ok = false; bool notOk = true; } +Mallocator alloc; +S* p = alloc.make!S(true, false); +scope(exit) alloc.dispose(p); +assert(p.ok); +assert(!p.notOk);
Alignment large enough for any scalar type.
In-place manipulation of slices.
Inserts at a given index in the slice while dropping its last element.
Shift elements in the slice by n > 0 positions to the left.
Shift all elements in the slice by n > 0 positions to the right.
Pops an elemens from a given index in the slice.
Inserts at a given index in the slice while dropping its last element.
Basically a macro for
slice[index .. $].shiftRight(1); +slice[index] = x;
static int[] a = [ 1, 2, 4, 5 ]; +a.shift(2, 3); +assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 3); assert(a[3] == 4);
Pops an elemens from a given index in the slice.
Basically a macro for
T temp = slice[index]; +slice[index .. $].shiftLeft(1); +return temp;
static int[] a = [ 1, 2, 3, 4 ]; +int extracted = a.unshift(2); +assert(extracted == 3); +assert(a[0] == 1); assert(a[1] == 2); assert(a[2] == 4);
Removes all elements and deallocates all memory for this tree.
If existing elements are structs with a destructor defined, those will be called.
B-tree data structure template.
B-trees are optimized for "cache friendliness" and low overhead per stored element. +The main tradeoff w.r.t other self-balancing trees is that insertions and +deletions from a B-tree will move multiple elements around per operation, +invalidating references and iterators. +When elements are big, consider storing them through indirect references.
In order to ensure all memory is deallocated, remember to call clear. +Alternatively, if stored elements don't need elaborate destruction, and the +provided allocator supports arenas, a full deallocation called externally will +not leave anything leaking (but beware of use-after-free bugs in this case).
While keeping duplicates is not the default, it can be used to implement multisets. +Just note that, if duplicate elements are allowed in the B-tree, they will have an +unspecified order among themselves (i.e. not related to order of insertion).
Removes all elements and deallocates all memory for this tree.
Iterates over elements in order. NOTE: should not be used while inserting or deleting elements from the tree.
Iterates over elements in order. NOTE: should not be used while inserting or deleting elements from the tree.
Check if the tree contains an element.
Element-wise comparison.
Gets the address of the first matching element, or null if it isn't in the tree.
Adds an element to the tree.
Removes (at most) one element from the tree.
Combined element hash.
Updates an element already in the set or creates a new one therein.
Returns the number of elements currently stored in the tree.
1 // tip: debug w/ visualizer at https://www.cs.usfca.edu/~galles/visualization/BTree.html +2 enum BTreeParameters params = { +3 nodeSlots: 3, +4 customCompare: true, +5 useBinarySearch: Ternary.yes, +6 }; +7 auto btree = BTree!(int, params)((ref a, ref b) => a - b); +8 static const payload = [ +9 34, 33, 38, +10 28, 27, 22, +11 30, 21, 24, +12 18, 19, 20, 26, 32, 42, +13 23, +14 ]; +15 +16 assert(btree.length == 0); +17 foreach (x; payload) { +18 // at first, the set does not contain x +19 assert(x !in btree); +20 assert(!btree.remove(x)); +21 // insert x and test returned address +22 int* p = btree.put(x); +23 assert(*p == x); +24 // now it does contain x, so test lookup +25 assert(x in btree); +26 assert(p == btree[x]); +27 // redundant insert is redundant +28 int* q = btree.put(x); +29 assert(q == p); +30 } +31 +32 // sanity check: the b-tree didn't come up with new elements we didn't insert +33 assert(btree.length == payload.length); +34 foreach (ref const x; btree) { +35 import std.algorithm.searching : canFind; +36 assert(payload.canFind(x)); +37 } +38 +39 // remove all but the last 3 elements in reverse order +40 for (int n = 1; n + 2 < payload.length; ++n) { +41 auto x = payload[$ - n]; +42 assert(x in btree); +43 btree.remove(x); +44 assert(x !in btree); +45 assert(btree.length == payload.length - n); +46 } +47 assert(btree.length == 3); +48 +49 // make sure we test aggregate equality +50 auto other = BTree!int(); +51 assert(btree != other); +52 import std.range.primitives : put; +53 static const remaining = [33, 34, 38]; +54 put(other, remaining); +55 assert(btree == other); +56 +57 // clear gets rid of the rest +58 btree.clear(); +59 assert(btree.length == 0); +60 foreach (x; payload) assert(x !in btree);
static struct S { + int x; + uint discriminator; + nothrow @nogc: + alias x this; + int opCmp(in S other) const => this.x - other.x; +} + +enum BTreeParameters params = { allowDuplicates: true }; +BTree!(S, params) multiset; +scope(exit) multiset.clear(); +static const payload = [ S(6), S(2), S(4), S(5), S(6, 9), S(4, 20) ]; + +assert(multiset.length == 0); +foreach (x; payload) { + S* p = multiset.put(x); + assert(*p == x); + assert(x in multiset); +} +assert(multiset.length == payload.length); + +assert(multiset.remove(S(4))); +assert(S(4) in multiset); +assert(multiset.remove(S(4))); +assert(S(4) !in multiset); +assert(multiset.length == payload.length - 2u); + +assert(multiset.remove(S(6))); +assert(multiset.remove(S(6))); +assert(!multiset.remove(S(6)));
Returns the number of elements currently stored in the tree.
Iterates over elements in order. NOTE: should not be used while inserting or deleting elements from the tree.
Iterates over elements in order. NOTE: should not be used while inserting or deleting elements from the tree.
Check if the tree contains an element.
Element-wise comparison.
Gets the address of the first matching element, or null if it isn't in the tree.
NOTE: returned pointer may be invalidated by any insertions or deletions.
Adds an element to the tree.
If the tree allows duplicates, this is an insertion; if it doesn't, this is an upsert.
NOTE:
A pointer to the stored element, or null in case of insertion failure.
Removes (at most) one element from the tree.
element being looked up in the tree
callback to cleanup after the element being removed (if found); + defaults to object.destroy.
Whether or not at least one x was contained in the tree.
Combined element hash.
Updates an element already in the set or creates a new one therein.
NOTE:
element being looked up
callback to create a new matching element to insert
callback to modify an existing element in the tree; only called + if not null; should never be provided if the tree allows duplicates
A pointer to the element currently stored in the set, whether it was updated or inserted. + This value is only null if the element would have been inserted but + the operation didn't succeed at some point (i.e. memory allocation failure).
Whether or not to allow duplicates in the B-tree; defaults to false.
Use a custom comparison function as an alternative to static + opCmp.
Static parameters for BTree template.
Whether or not to allow duplicates in the B-tree; defaults to false.
Use a custom comparison function as an alternative to static + opCmp.
Max elements stored per node, must be at least 2. Use size_t.max for default.
Whether to use a binary intra-node search. Use Ternary.unknown for default.
Max elements stored per node, must be at least 2. Use size_t.max for default.
Whether to use a binary intra-node search. Use Ternary.unknown for default.
Generic B-tree data structure.
B-tree data structure template.
Static parameters for BTree template.
Zero-sized type carrying no information at all.
NOTE: Make sure not to use this in extern (C) signatures, as the ABI is unspecified.
Phobos move, but always by destructive copy when in debug mode.
Performs the same operations as core.lifetime.move, but when in debug mode the +moved source is always set to its .init value, which is easier to check (e.g. +null for pointers) when looking for referential integrity bugs.
int x = 1; +int* p = &x; +int* q = null; +move(p, q); +assert(q == &x); +debug assert(p == null); // only in debug mode!
Phobos move, but always by destructive copy when in debug mode.
Performs the same operations as core.lifetime.move, but when in debug mode the +moved source is always set to its .init value, which is easier to check (e.g. +null for pointers) when looking for referential integrity bugs.
int x = 1; +int* p = &x; +int* q = null; +move(p, q); +assert(q == &x); +debug assert(p == null); // only in debug mode!
Free-function version of opCmp +for generic code.
Can be used to efficiently compare both complex types with a custom opCmp, or primitive types.
import std.meta : AliasSeq; +static foreach (Scalar; AliasSeq!(char, ubyte, int, size_t, float, double)) {{ + const Scalar two = 2; + const Scalar three = 3; + assert( opCmp(two, three) < 0 ); + assert( opCmp(three, two) > 0 ); + assert( opCmp(two, two) == 0 ); + assert( opCmp(two, three) != 0 ); +}}
A non-standard library for DasBetterC.
This is the library I wish I had when I started using D as a better alternative and complement to C.
Custom memory allocators and related helpers.
In-place manipulation of slices.
Generic B-tree data structure.
Core type definitions, templates and helper procedures.
Miscellaneous numeric math.
The following list ranks the goals of this project, in order of importance:
Rationale for the first point is that it allows C developers to use D-generated code in their apps and libraries, +even if that may require some explicit template instantations, manual symbol mangling directives and extern(C). +The other goals constitute reasons for wanting to use this library in C or D codebases in the first place.
Since I still value my time and sanity, I gave up on trying to partition this library into DUB subpackages. +So, if you want to use any particular module here without the rest of the project, +just make sure you carry its dependency subtree along with it. +Here's a dependency graph (forest) to help with that.
Number of accumulated values.
Tracks a stream of values and computes some statistics in constant space.
Accumulate a given (non-NaN) value.
Accumulate a given (non-NaN) value.
Number of accumulated values.
Biggest accumulated value.
Average accumulated value.
Smallest accumulated value.
Population standard deviation.
Sample standard deviation.
Sample variance.
Population variance.
import std.range.primitives : put, isOutputRange; +import std.math.operations : isClose; + +Accumulator small, big; +static assert(isOutputRange!(Accumulator, double)); + +static const double[] smallNumbers = [ 4, 7, 13, 16 ]; +put(small, smallNumbers); + +static const double[] bigNumbers = [ // same as smallnumbers + 1e9 + 1.000000004e9, 1.000000007e9, 1.000000013e9, 1.000000016e9 ]; +put(big, bigNumbers); + +assert(isClose(small.count, big.count )); +assert(isClose(small.min + 1e9, big.min )); +assert(isClose(small.max + 1e9, big.max )); +assert(isClose(small.mean + 1e9, big.mean )); +assert(isClose(small.var, big.var )); +assert(isClose(small.variance, big.variance )); +assert(isClose(small.std, big.std )); +assert(isClose(small.standardDeviation, big.standardDeviation));
Biggest accumulated value.
Average accumulated value.
Smallest accumulated value.
Accumulate a given (non-NaN) value.
Accumulate a given (non-NaN) value.
Population standard deviation.
Sample standard deviation.
Sample variance.
Population variance.
Miscellaneous numeric math.
Tracks a stream of values and computes some statistics in constant space.
Minimum alignment of all allocated memory blocks.