summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-slice-index-map.cpp
blob: d147556e4ea862efba14812192a901719533786a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "slang-string-slice-index-map.h"

namespace Slang
{

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringSliceIndexMap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

StringSliceIndexMap::CountIndex StringSliceIndexMap::add(const UnownedStringSlice& key, Index valueIndex)
{
    StringSlicePool::Handle handle;
    m_pool.findOrAdd(key, handle);
    const CountIndex countIndex = StringSlicePool::asIndex(handle);
    if (countIndex >= m_indexMap.getCount())
    {
        SLANG_ASSERT(countIndex == m_indexMap.getCount());
        m_indexMap.add(valueIndex);
    }
    else
    {
        m_indexMap[countIndex] = valueIndex;
    }
    return countIndex;
}

StringSliceIndexMap::CountIndex StringSliceIndexMap::findOrAdd(const UnownedStringSlice& key, Index defaultValueIndex)
{
    StringSlicePool::Handle handle;
    m_pool.findOrAdd(key, handle);
    const CountIndex countIndex = StringSlicePool::asIndex(handle);
    if (countIndex >= m_indexMap.getCount())
    {
        SLANG_ASSERT(countIndex == m_indexMap.getCount());
        m_indexMap.add(defaultValueIndex);
    }
    return countIndex;
}

void StringSliceIndexMap::clear()
{
    m_pool.clear();
    m_indexMap.clear();
}

} // namespace Slang