structstd.hash_map.HashMapUnmanaged.Iterator[src]

Fields

hm: *const Self
index: Size = 0

Functions

Functionnext[src]

pub fn next(it: *Iterator) ?Entry

Parameters

Source Code

Source code
pub fn next(it: *Iterator) ?Entry {
    assert(it.index <= it.hm.capacity());
    if (it.hm.size == 0) return null;

    const cap = it.hm.capacity();
    const end = it.hm.metadata.? + cap;
    var metadata = it.hm.metadata.? + it.index;

    while (metadata != end) : ({
        metadata += 1;
        it.index += 1;
    }) {
        if (metadata[0].isUsed()) {
            const key = &it.hm.keys()[it.index];
            const value = &it.hm.values()[it.index];
            it.index += 1;
            return Entry{ .key_ptr = key, .value_ptr = value };
        }
    }

    return null;
}

Source Code

Source code
pub const Iterator = struct {
    hm: *const Self,
    index: Size = 0,

    pub fn next(it: *Iterator) ?Entry {
        assert(it.index <= it.hm.capacity());
        if (it.hm.size == 0) return null;

        const cap = it.hm.capacity();
        const end = it.hm.metadata.? + cap;
        var metadata = it.hm.metadata.? + it.index;

        while (metadata != end) : ({
            metadata += 1;
            it.index += 1;
        }) {
            if (metadata[0].isUsed()) {
                const key = &it.hm.keys()[it.index];
                const value = &it.hm.values()[it.index];
                it.index += 1;
                return Entry{ .key_ptr = key, .value_ptr = value };
            }
        }

        return null;
    }
}