Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 55 lines (45 sloc) 1.579 kB
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
1 #ifndef RBX_SYMBOLTABLE_HPP
2 #define RBX_SYMBOLTABLE_HPP
3
4 #include "oop.hpp"
5 #include "prelude.hpp"
6
7 #include <string>
8 #include <vector>
a645f80 @brixen Changed SymbolTable to use unordered_map. Added docs.
brixen authored
9 #include <tr1/unordered_map>
10
11 /* SymbolTable provides a one-to-one map between a symbol ID
12 * and a string. The hashing algorithm used to generate a
13 * hashval from a string is not perfect. For instance, the
14 * strings "__uint_fast64_t" and "TkIF_MOD" generate the same
15 * hashval. SymbolTable handles this by first looking up a
16 * symbol ID for a string by the string's hashval and then
17 * comparing the candidate string with the stored string that
18 * corresponds to the possible symbol ID.
19 *
20 * When a symbol ID is generated, the string corresponding to
21 * that symbol ID is stored in a vector. The symbol ID is the
22 * index of that string in the vector. The symbol ID becomes
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
23 * a Symbol* by adding the tag value for symbols. (See builtin
a645f80 @brixen Changed SymbolTable to use unordered_map. Added docs.
brixen authored
24 * class Symbol::from_index and oop.hpp.)
25 */
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
26 namespace rubinius {
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
27
58105ff @brixen Added Symbol::all_symbols primitive and fixed up Ruby Symbol code.
brixen authored
28 class Array;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
29 class String;
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
30 class Symbol;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
31
0053c4b @brixen Use explicit reference to vector in SymbolTable.
brixen authored
32 typedef std::vector<std::string> SymbolStrings;
33 typedef std::vector<std::size_t> SymbolIds;
34 typedef std::tr1::unordered_map<hashval, SymbolIds> SymbolMap;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
35
36 class SymbolTable {
37 public:
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
38 Symbol* lookup(STATE, std::string str);
39 Symbol* lookup(STATE, const char* str);
40 Symbol* lookup(STATE, String* str);
58105ff @brixen Added Symbol::all_symbols primitive and fixed up Ruby Symbol code.
brixen authored
41 String* lookup_string(STATE, Symbol* sym);
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
42 const char* lookup_cstring(STATE, Symbol* sym);
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
43 size_t size();
58105ff @brixen Added Symbol::all_symbols primitive and fixed up Ruby Symbol code.
brixen authored
44 Array* all_as_array(STATE);
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
45
46 private:
0053c4b @brixen Use explicit reference to vector in SymbolTable.
brixen authored
47 SymbolMap symbols;
48 SymbolStrings strings;
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
49
50 size_t add(std::string str);
51 };
52 };
53
54 #endif
Something went wrong with that request. Please try again.