Ignore:
Timestamp:
Jun 28, 2015, 3:55:39 PM (4 years ago)
Author:
nmedfort
Message:

Bug fix for CC insert_range and UnicodeSet? iterator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/unicode_set.h

    r4620 r4621  
    3434}
    3535
    36 typedef uint32_t bitquad_t;
     36namespace UCD {
    3737
    38 // The representation for runs
    3938enum run_type_t : uint16_t {Empty, Mixed, Full};
    40 
    41 struct RunStructure {
    42   RunStructure(run_type_t r, uint16_t lgth) : mType(r), mRunLength(lgth) {}
    43   run_type_t mType;
    44   uint16_t mRunLength;
    45 };
    4639
    4740class UnicodeSet {
    4841public:
    4942
     43    using bitquad_t = uint32_t;
     44    using length_t = uint16_t;
     45    using run_t = std::pair<run_type_t, length_t>;
     46
    5047    using codepoint_t = re::codepoint_t;
    5148    using interval_t = re::interval_t;
    52     using RunVector = std::vector<RunStructure>;
     49    using RunVector = std::vector<run_t>;
    5350    using QuadVector = std::vector<bitquad_t>;
    5451
     
    5956        iterator(RunVector::const_iterator runIterator, QuadVector::const_iterator quadIterator)
    6057        : mRunIterator(runIterator), mQuadIterator(quadIterator)
    61         , mQuadOffset(0), mQuadPosition(0), mBaseCodePoint(0), mMinCodePoint(0), mMaxCodePoint(0)
     58        , mMixedRunIndex(0), mQuadOffset(0), mBaseCodePoint(0), mMinCodePoint(0), mMaxCodePoint(0)
    6259        {
    6360
     
    7572
    7673        inline bool equal(iterator const & other) const {
    77             return (mRunIterator == other.mRunIterator) && (mQuadIterator == other.mQuadIterator);
     74            return (mRunIterator == other.mRunIterator) && (mQuadIterator == other.mQuadIterator) &&
     75                   (mMixedRunIndex == other.mMixedRunIndex) && (mQuadOffset == other.mQuadOffset);
    7876        }
    7977    private:
    80         RunVector::const_iterator           mRunIterator;
    81         const RunVector::const_iterator     mRunEnd;
    82         QuadVector::const_iterator          mQuadIterator;
    83 
    84 
    85         bitquad_t                   mQuadOffset;
    86         unsigned                    mQuadPosition;
    87         unsigned                    mBaseCodePoint;
    88         re::codepoint_t             mMinCodePoint;
    89         re::codepoint_t             mMaxCodePoint;
     78        RunVector::const_iterator   mRunIterator;
     79        QuadVector::const_iterator  mQuadIterator;
     80        unsigned                    mMixedRunIndex;
     81        bitquad_t                   mQuadOffset;       
     82        codepoint_t                 mBaseCodePoint;
     83        codepoint_t                 mMinCodePoint;
     84        codepoint_t                 mMaxCodePoint;
    9085    };
    9186
     
    9994    }
    10095
    101     class quad_iterator : public boost::iterator_facade<quad_iterator, std::pair<RunStructure, bitquad_t>, boost::random_access_traversal_tag> {
     96    class quad_iterator : public boost::iterator_facade<quad_iterator, std::pair<run_t, bitquad_t>, boost::random_access_traversal_tag> {
    10297        friend class UnicodeSet;
    10398        friend class boost::iterator_core_access;
     
    108103        void advance(unsigned n);
    109104
    110         inline const std::pair<RunStructure, bitquad_t> dereference() const {
     105        inline const std::pair<run_t, bitquad_t> dereference() const {
    111106            return std::make_pair(getRun(), getQuad());
    112107        }
     
    116111        }
    117112
    118         inline RunStructure getRun() const {
     113        inline run_t getRun() const {
    119114            const auto & t = *mRunIterator;
    120             return RunStructure(t.mType, t.mRunLength - mOffset);
     115            return std::make_pair(std::get<0>(t), std::get<1>(t) - mOffset);
    121116        }
    122117
     
    147142    void dump(llvm::raw_ostream & out) const;
    148143
    149     UnicodeSet complement() const;
    150     UnicodeSet operator & (const UnicodeSet & other) const;
    151     UnicodeSet operator + (const UnicodeSet & other) const;
    152     UnicodeSet operator - (const UnicodeSet & other) const;
    153     UnicodeSet operator ^ (const UnicodeSet & other) const;
     144    UnicodeSet operator~() const;
     145    UnicodeSet operator&(const UnicodeSet & other) const;
     146    UnicodeSet operator+(const UnicodeSet & other) const;
     147    UnicodeSet operator-(const UnicodeSet & other) const;
     148    UnicodeSet operator^(const UnicodeSet & other) const;
     149    UnicodeSet operator==(const UnicodeSet & other) const;
    154150
    155151    UnicodeSet();
    156152    UnicodeSet(const codepoint_t codepoint);
    157153    UnicodeSet(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint);
    158     UnicodeSet(std::initializer_list<RunStructure> r, std::initializer_list<bitquad_t> q) : mRuns(r), mQuads(q) {}
    159     UnicodeSet(std::vector<RunStructure> && r, std::vector<bitquad_t> && q) : mRuns(r), mQuads(q) {}
     154    UnicodeSet(std::initializer_list<run_t> r, std::initializer_list<bitquad_t> q) : mRuns(r), mQuads(q) {}
     155    UnicodeSet(std::vector<run_t> && r, std::vector<bitquad_t> && q) : mRuns(r), mQuads(q) {}
     156
     157    inline void swap(UnicodeSet & other);
     158    inline void swap(UnicodeSet && other);
    160159
    161160private:
    162161
    163     std::vector<RunStructure>   mRuns;
     162    std::vector<run_t>   mRuns;
    164163    std::vector<bitquad_t>      mQuads;
    165164};
    166165
     166inline void UnicodeSet::swap(UnicodeSet & other) {
     167    mRuns.swap(other.mRuns);
     168    mQuads.swap(other.mQuads);
     169}
     170
     171inline void UnicodeSet::swap(UnicodeSet && other) {
     172    mRuns.swap(other.mRuns);
     173    mQuads.swap(other.mQuads);
     174}
     175
    167176inline UnicodeSet uset_complement(const UnicodeSet & s) {
    168     return s.complement();
     177    return ~s;
    169178}
    170179
     
    185194}
    186195
     196}
     197
    187198#endif
    188199
Note: See TracChangeset for help on using the changeset viewer.