-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTokenPool.h
More file actions
30 lines (24 loc) · 751 Bytes
/
TokenPool.h
File metadata and controls
30 lines (24 loc) · 751 Bytes
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
//
// FormulaEngine Project
// By Mike Lewis - 2015
//
// Mapper for condensing strings to unique unsigned integer IDs
//
// Given an input string, the token pool is designed to return a
// unique but stable ID - that is, if the same string is provided
// to the token pool later on, the same ID should be retured.
//
// Moreover, the token pool must support going from a unique ID
// back to the original string.
//
#pragma once
class TokenPool {
public:
unsigned AddToken (const char str[]);
unsigned AddToken (const std::string & str);
unsigned FindToken (const std::string & str);
const std::string & GetStringFromToken (unsigned token) const;
private:
std::vector<std::string> m_pool;
std::map<std::string, unsigned> m_fastLookup;
};