HashRangeMap

Provides a mapping from HashRange to the specified type

Note: Unittests for put, remove and opopBinaryRight!"in" are not placed directly in this struct as they depend on the assumption that type Value (the template argument) has a meaningful equality operator (opEquals). Instead, private external functions exist to test these methods. These are then called on HashRangeMaps with various different types of Value, in a unittest block outside the struct.

Members

Functions

clear
void clear()

Clear entirely the HashRangeMap

empty
bool empty()

Tells whether the HashRangeMap is empty.

hasGap
bool hasGap()

Check if the hash ranges in the map have any gaps between them or boundaries of hash_t type.

hasOverlap
bool hasOverlap()

Check if there is any overlap between the hash ranges in the map

isTessellated
bool isTessellated()

Check if the hash ranges in the map have neither gaps nor overlaps and cover the whole space of hash_t values.

length
size_t length()
opApply
int opApply(int delegate(ref HashRange r, ref Value v) dg)

foreach iterator over ranges and corresponding values. This iterator prevents true ref iteration over the keys of the internal map by passing a copy of the range to the iteration delegate.

opBinaryRight
Value* opBinaryRight(HashRange range)

'in' operator: looks up the value mapped by a given HashRange

put
Value* put(HashRange range, bool added)

Looks up the mapping for non-empty range or adds one if not found

remove
bool remove(HashRange range)

Removes the mapping for the specified range

Parameters

Value

type to store in values of map

Examples

test instantiation with int

HashRangeMap!(int) ihrm;

testPut([1, 2, 3, 4, 5, 6, 7, 8][]);
testRemove([1, 2, 3, 4, 5][]);
testOpInR([1, 2, 3, 4, 5][]);
testOpApply([1, 2, 3, 4, 5][]);

test instantiation with ulong

HashRangeMap!(ulong) uhrm;

testPut([1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL]);
testRemove([1UL, 2UL, 3UL, 4UL, 5UL]);
testOpInR([1UL, 2UL, 3UL, 4UL, 5UL]);
testOpApply([1UL, 2UL, 3UL, 4UL, 5UL]);

test instantiation with float

HashRangeMap!(float) fhrm;

testPut([1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f]);
testRemove([1.0f, 2.0f, 3.0f, 4.0f, 5.0f]);
testOpInR([1.0f, 2.0f, 3.0f, 4.0f, 5.0f]);
testOpApply([1.0f, 2.0f, 3.0f, 4.0f, 5.0f]);

test instantiation with pointer

int v1, v2, v3, v4, v5, v6, v7, v8;
HashRangeMap!(int*) phrm;

testPut([&v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8]);
testRemove([&v1, &v2, &v3, &v4, &v5]);
testOpInR([&v1, &v2, &v3, &v4, &v5]);
testOpApply([&v1, &v2, &v3, &v4, &v5]);

test instantiation with arbitrary struct that supports opEquals

static struct S
{
    import ocean.util.Convert;

    int x;

    static S opCall(int x)
    {
        S s;
        s.x = x;
        return s;
    }

    equals_t opEquals(S other)
    {
        return this.x == other.x;
    }

    istring toString()
    {
        return "S(" ~ to!(istring)(this.x) ~ ")";
    }
}

HashRangeMap!(S) shrm;

testPut([S(1), S(2), S(3), S(4), S(5), S(6), S(7), S(8)]);
testRemove([S(1), S(2), S(3), S(4), S(5)]);
testOpInR([S(1), S(2), S(3), S(4), S(5)]);
testOpApply([S(1), S(2), S(3), S(4), S(5)]);

test instantiation with array

HashRangeMap!(int[]) arhrm;

testPut([[1], [2, 1], [3, 1, 2], [4], [5], [6], [7], [8]]);
testRemove([[1], [2, 1], [3, 1, 2], [4], [5]]);
testOpInR([[1], [2, 1], [3, 1, 2], [4], [5]]);
testOpApply([[1], [2, 1], [3, 1, 2], [4], [5]]);

Meta