containers.openhashset

Open-Addressed Hash Set

Authors

Brian Schott

  • Declaration

    struct OpenHashSet(T, Allocator = Mallocator, alias hashFunction = generateHash!T, bool supportGC = shouldAddGCRange!T);

    Simple open-addressed hash set. Use this instead of HashSet when the size and quantity of the data to be inserted is small.

    Parameters

    T

    the element type of the hash set

    Allocator

    the allocator to use. Defaults to Mallocator.

    hashFunction

    the hash function to use

    supportGC

    if true, calls to GC.addRange and GC.removeRange will be used to ensure that the GC does not accidentally free memory owned by this container.

    • Declaration

      this(Allocator allocator);

      Use the given allocator for allocations.

    • Declaration

      this(size_t initialCapacity, Allocator allocator);

      Initializes the hash set with the given initial capacity.

      Parameters

      size_t initialCapacity

      the initial capacity for the hash set

    • Declaration

      void clear();

      Removes all items from the hash set.

    • Declaration

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

    • Declaration

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

    • Declaration

      const bool contains(T item);
      inout bool opBinaryRight(string op)(T item) if (op == "in");

      Return Value

      true if the hash set contains the given item, false otherwise.

    • Declaration

      bool insert(T item);
      alias put = insert;
      alias insertAnywhere = insert;
      bool opOpAssign(string op)(T item) if (op == "~");

      Inserts the given item into the set.

      Return Value

      true if the item was inserted, false if it was already present.

    • Declaration

      bool remove(T item);

      Parameters

      T item

      the item to remove

      Return Value

      true if the item was removed, false if it was not present

    • Declaration

      pure nothrow @nogc @safe auto opSlice(this This)();

      Return Value

      A range over the set.