Ignore:
Timestamp:
Oct 4, 2015, 4:59:28 PM (4 years ago)
Author:
nmedfort
Message:

First stage of CC_NameMap removal

File:
1 moved

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_memoizer.hpp

    r4818 r4819  
    22#define RE_NAMEDICTIONARY_H
    33
     4#include <re/re_name.h>
     5#include <set>
     6
    47namespace re {
    58
    6 class NameDictionary
    7 {
    8 public:
    9     NameDictionary();
     9namespace {
     10
     11struct MemoizerComparator {
     12    inline bool operator() (const RE * lh, const RE * rh) const{
     13        if (LLVM_LIKELY(isa<Name>(lh) && isa<Name>(rh))) {
     14            return *cast<Name>(lh) < *cast<Name>(rh);
     15        } else if (isa<Name>(lh)) {
     16            return *cast<Name>(lh) < *cast<CC>(rh);
     17        }
     18        return !(*cast<Name>(rh) < *cast<CC>(lh));
     19    }
     20};
     21
     22}
     23
     24struct Memoizer : private std::set<RE *, MemoizerComparator> {
     25
     26    inline Name * memoize(CC * cc) {
     27        auto f = find(cc);
     28        if (f != end()) {
     29            return cast<Name>(*f);
     30        } else {
     31            Name * name = makeName(cc->canonicalName(CC_type::UnicodeClass), cc);
     32            insert(name);
     33            return name;
     34        }
     35    }
     36
     37    inline Name * memoize(Name * name) {
     38        return cast<Name>(*insert(name).first);
     39    }
    1040};
    1141
Note: See TracChangeset for help on using the changeset viewer.