Ignore:
Timestamp:
Jun 23, 2015, 9:29:39 AM (4 years ago)
Author:
nmedfort
Message:

Replaced CharSetItem? with a std::pair.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4612 r4614  
    1616namespace re {
    1717
    18 typedef unsigned codepoint_t;
    19 
    20 struct CharSetItem {
    21     constexpr CharSetItem() : lo_codepoint(0), hi_codepoint(0) {}
    22     constexpr CharSetItem(const codepoint_t lo, const codepoint_t hi) : lo_codepoint(lo), hi_codepoint(hi) {}
    23     constexpr codepoint_t operator [](const unsigned i) const {
    24         return (i == 0) ? lo_codepoint : (i == 1) ? hi_codepoint : throw std::runtime_error("CharSetItem[] can only accept 0 or 1.");
    25     }
    26     codepoint_t lo_codepoint;
    27     codepoint_t hi_codepoint;
    28 };
     18using codepoint_t = unsigned;
     19using interval_t = std::pair<codepoint_t, codepoint_t>;
    2920
    3021enum CC_type {UnicodeClass, ByteClass};
     
    4031    }
    4132
    42     using CharSetAllocator = SlabAllocator<CharSetItem>;
    43     using CharSetVector = std::vector<CharSetItem, CharSetAllocator>;
    44 
    45     typedef CharSetVector::iterator                 iterator;
    46     typedef CharSetVector::const_iterator           const_iterator;
    47     typedef CharSetVector::size_type                size_type;
    48     typedef CharSetVector::reference                reference;
    49     typedef CharSetVector::const_reference          const_reference;
     33    using IntervalAllocator = SlabAllocator<interval_t>;
     34    using IntervalVector = std::vector<interval_t, IntervalAllocator>;
     35
     36    using iterator = IntervalVector::iterator;
     37    using const_iterator = IntervalVector::const_iterator;
     38    using size_type = IntervalVector::size_type;
     39    using reference = IntervalVector::reference;
     40    using const_reference = IntervalVector::const_reference;
    5041
    5142    static const codepoint_t UNICODE_MAX = 0x10FFFF;
     
    5344    std::string canonicalName(const CC_type type) const;
    5445
    55     CharSetItem & operator [](unsigned i) {
     46    interval_t & operator [](unsigned i) {
    5647        return mSparseCharSet[i];
    5748    }
    5849
    59     const CharSetItem & operator [](unsigned i) const {
     50    const interval_t & operator [](unsigned i) const {
    6051        return mSparseCharSet[i];
    6152    }
    6253
    6354    inline codepoint_t min_codepoint() const {
    64         return mSparseCharSet.size() == 0 ? 0 : mSparseCharSet.front().lo_codepoint;
     55        return empty() ? 0 : std::get<0>(front());
    6556    }
    6657
    6758    inline codepoint_t max_codepoint() const {
    68         return mSparseCharSet.size() == 0 ? 0 : mSparseCharSet.back().hi_codepoint;
    69     }
    70 
    71     void insert_range(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint);
    72 
    73     void remove_range(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint);
     59        return empty() ? 0 : std::get<1>(back());
     60    }
     61
     62    void insert_range(const codepoint_t lo, const codepoint_t hi);
     63
     64    void remove_range(const codepoint_t lo, const codepoint_t hi);
    7465
    7566    inline void insert(const codepoint_t codepoint) {
     
    154145    }
    155146    CC(const CC * cc1, const CC * cc2);
     147
    156148private:   
    157     CharSetVector mSparseCharSet;
    158     static CharSetAllocator mCharSetAllocator;
     149    IntervalVector mSparseCharSet;
     150    static IntervalAllocator mCharSetAllocator;
    159151};
    160152
     
    175167}
    176168
     169inline codepoint_t & lo_codepoint(CC::reference i) {
     170    return std::get<0>(i);
     171}
     172inline codepoint_t lo_codepoint(CC::const_reference i) {
     173    return std::get<0>(i);
     174}
     175inline codepoint_t & lo_codepoint(const CC::iterator i) {
     176    return lo_codepoint(*i);
     177}
     178inline codepoint_t lo_codepoint(const CC::const_iterator i) {
     179    return lo_codepoint(*i);
     180}
     181
     182inline codepoint_t & hi_codepoint(CC::reference i) {
     183    return std::get<1>(i);
     184}
     185inline codepoint_t hi_codepoint(CC::const_reference i) {
     186    return std::get<1>(i);
     187}
     188inline codepoint_t & hi_codepoint(const CC::iterator i) {
     189    return hi_codepoint(*i);
     190}
     191inline codepoint_t hi_codepoint(const CC::const_iterator i) {
     192    return hi_codepoint(*i);
     193}
    177194
    178195
     
    201218}
    202219
    203 CC * subtractCC(const CC * cc1, const CC * cc2);
     220CC * subtractCC(const CC * a, const CC * b);
    204221   
    205222CC * intersectCC(const CC * cc1, const CC * cc2);
Note: See TracChangeset for help on using the changeset viewer.