summary refs log tree commit diff stats
path: root/identifier.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:31:34 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:31:34 -0500
commit9758b85c55b005a18d91acb4508f2c6b76dba3e2 (patch)
treef2e1f4f4a6eb8cb53b612d2e2d7ecc2c666d8b4d /identifier.h
parentd7e934156858287cdb7597ad0dced97d4d279f2f (diff)
downloadaspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.tar.gz
aspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.tar.bz2
aspartame-9758b85c55b005a18d91acb4508f2c6b76dba3e2.zip
librawr provides identifier
Diffstat (limited to 'identifier.h')
-rw-r--r--identifier.h59
1 files changed, 0 insertions, 59 deletions
diff --git a/identifier.h b/identifier.h deleted file mode 100644 index 74d83ce..0000000 --- a/identifier.h +++ /dev/null
@@ -1,59 +0,0 @@
1#ifndef IDENTIFIER_H_D7EE5679
2#define IDENTIFIER_H_D7EE5679
3
4#include <map>
5#include <vector>
6
7template <typename T>
8class identifier {
9public:
10
11 using value_type = T;
12
13private:
14
15 using vector_type = std::vector<value_type>;
16
17public:
18
19 using key_type = typename vector_type::size_type;
20
21 key_type add(const value_type& val)
22 {
23 auto it = ids_.find(val);
24
25 if (it == std::end(ids_))
26 {
27 key_type ret = ids_.size();
28 ids_[val] = ret;
29
30 uniq_.push_back(val);
31
32 return ret;
33 } else {
34 return it->second;
35 }
36 }
37
38 void compile()
39 {
40 ids_.clear();
41 }
42
43 inline const value_type& get(key_type i) const
44 {
45 return uniq_.at(i);
46 }
47
48 inline key_type size() const
49 {
50 return uniq_.size();
51 }
52
53private:
54
55 std::map<value_type, key_type> ids_;
56 vector_type uniq_;
57};
58
59#endif /* end of include guard: IDENTIFIER_H_D7EE5679 */