ocean.util.container.map.Map

Template for a class implementing a mapping from a user-specified type to a user-specified type.

The interface of the class has been kept deliberately simple, purely handling the management of the mapping. The handling of the mapping values is left entirely up to the user -- all methods simply return a pointer to the mapping value which the user can do what they like with. (This is an intentional design decision, in order to reduce the complexity of the template.)

The HashMap is designed as a replacement for ocean.core.ArrayMap. It has several advantages: 1. Memory safety. As the ArrayMap's buckets are implemented as dynamic arrays, each bucket will theoretically grow continually in size over extended periods of use. Even when clear()ed, the buffers allocated for the buckets will not reduce in size. The HashMap, on the other hand, uses a pool of elements, meaning that the memory allocated for each bucket is truly variable. 2. Code simplicity via removing optional advanced features such as thread safety and value array copying. 3. Extensibility. Functionality is split into several modules, including a base class for easier reuse of components.

Usage example with various types stored in mapping:

import ocean.util.container.map.HashMap;

// Mapping from hash_t -> int
auto map = new HashMap!(int);

hash_t hash = 232323;

// Add a mapping
*(map.put(hash)) = 12;

// Check if a mapping exists (null if not found)
auto exists = hash in map;

// Remove a mapping
map.remove(hash);

// Clear the map
map.clear();

// Mapping from hash_t -> char[]
auto map2 = new HashMap!(char[]);

// Add a mapping
map2.put(hash).copy("hello");

// Mapping from hash_t -> struct
struct MyStruct
{
    int x;
    float y;
}

auto map3 = new HashMap!(MyStruct);

// Add a mapping
*(map3.put(hash)) = MyStruct(12, 23.23);

Members

Classes

Map
class Map(V, K)

Map class template to store values of a certain type. Manages a mapping from K to V, leaving the hash function implementation to the subclass (abstract BucketSet.toHash()).

Map
class Map(size_t V, K)

HashMap class template to store the raw data of values of a certain size. Manages a mapping from K to ubyteV, leaving the hash function implementation to the subclass (abstract BucketSet.toHash()). Since static arrays cannot be returned, the access methods return a void[] slice to the value.

StandardKeyHashingMap
class StandardKeyHashingMap(V, K)

StandardKeyHashingMap class template. Manages a mapping from K to V, using a standard way of hash calculation:

StandardKeyHashingMap
class StandardKeyHashingMap(size_t V, K)

StandardKeyHashingMap class template. Manages a mapping from K to ubyteV, using a standard way of hash calculation:

Functions

test_key
void test_key()

Test key types smaller than size_t (or even equals) don't screw up the alignment and makes impossible to the GC to scan pointers in the value.

test_val
void test_val()

Test key types smaller than size_t (or even equals) don't screw up the alignment and makes impossible to the GC to scan pointers in the value.

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).