containers.treemap

Tree Map

Authors

Brian Schott

  • Declaration

    struct TreeMap(K, V, Allocator = Mallocator, alias less = "a < b", bool supportGC = shouldAddGCRange!K || shouldAddGCRange!V, size_t cacheLineSize = 64);

    A key→value mapping where the keys are guaranteed to be sorted.

    Parameters

    K

    the key type

    V

    the value type

    Allocator

    the allocator to use. Defaults to Mallocator.

    less

    the key comparison function to use

    supportGC

    true to support storing GC-allocated objects, false otherwise

    cacheLineSize

    the size of the internal nodes in bytes

    • Declaration

      this();

      No default construction if an allocator must be provided.

    • Declaration

      this(Allocator allocator);

      Use the given allocator for allocations.

    • Declaration

      @trusted void insert(const K key, V value);

      Inserts or overwrites the given key-value pair.

    • Declaration

      void opIndexAssign(V value, const K key);

      Supports treeMap[key] = value; syntax.

    • Declaration

      inout auto opIndex(this This)(const K key);

      Supports treeMap[key] syntax.

      Throws

      RangeError if the key does not exist.

    • get

      Declaration

      inout @trusted auto get(this This)(const K key, lazy V defaultValue);

      Return Value

      the value associated with the given key, or the given defaultValue.

    • Declaration

      @safe auto getOrAdd(this This)(const K key, lazy V value);

      If the given key does not exist in the TreeMap, adds it with the value defaultValue.

      Parameters

      K key

      the key to look up

      V value

      the default value

    • Declaration

      bool remove(const K key);

      Removes the key→value mapping for the given key.

      Parameters

      K key

      the key to remove

      Return Value

      true if the key existed in the map

    • Declaration

      inout pure nothrow @nogc @trusted bool containsKey(const K key);

      Return Value

      true if the mapping contains the given key

    • Declaration

      const pure nothrow @nogc @property @safe bool empty();

      Return Value

      true if the mapping is empty

    • Declaration

      inout pure nothrow @nogc @property @safe size_t length();

      Return Value

      the number of key→value pairs in the map

    • Declaration

      inout pure @property @trusted auto keys(this This)();

      Return Value

      a GC-allocated array of the keys in the map

    • Declaration

      inout pure @nogc @trusted auto byKey(this This)();

      Return Value

      a range of the keys in the map

    • Declaration

      inout pure @property @trusted auto values(this This)();

      Return Value

      a GC-allocated array of the values in the map

    • Declaration

      inout pure @nogc @trusted auto byValue(this This)();
      alias opSlice = byValue;

      Return Value

      a range of the values in the map

    • Declaration

      inout pure @trusted auto byKeyValue(this This)();

      Return Value

      a range of the kev/value pairs in this map. The element type of this range is a struct with key and value fields.