BTree.upsert

Updates an element already in the set or creates a new one therein.

NOTE:

  • Returned pointer may be invalidated by any following insertions or deletions.
  • Allocation failure is irrecoverable in this implementation.
struct BTree(T, BTreeParameters params = BTreeParameters.init, Allocator = Mallocator)
T*
upsert
(
in T x
,
scope T delegate
()
nothrow @nogc
create
,
scope void delegate
(
ref T
)
nothrow @nogc
update = null
)
out (p) { assert ((p == null) || (*p in this)); }

Parameters

x T

element being looked up

create T delegate
()
nothrow @nogc

callback to create a new matching element to insert

update void delegate
(
ref T
)
nothrow @nogc

callback to modify an existing element in the tree; only called if not null; should never be provided if the tree allows duplicates

Return Value

Type: T*

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).