| 21 | bool _exists; |
| 22 | public: |
| 23 | class Iterator { |
| 24 | ObjectContents *parent; |
| 25 | std::map<uint64_t, unsigned int>::iterator iter; |
| 26 | unsigned int current_state; |
| 27 | int current_val; |
| 28 | uint64_t pos; |
| 29 | private: |
| 30 | unsigned int get_state(uint64_t pos); |
| 31 | public: |
| 32 | explicit Iterator(ObjectContents *parent) : |
| 33 | parent(parent), iter(parent->seeds.end()), |
| 34 | current_state(0), current_val(0), pos(-1) { |
| 35 | seek_to_first(); |
| 36 | } |
| 37 | char operator*() { |
| 38 | return parent->written.contains(pos) ? |
| 39 | static_cast<char>(current_val % 256) : '\0'; |
| 40 | } |
| 41 | uint64_t get_pos() { |
| 42 | return pos; |
| 43 | } |
| 44 | void seek_to(uint64_t _pos) { |
| 45 | if (pos > _pos || |
| 46 | (iter != parent->seeds.end() && _pos >= iter->first)) { |
| 47 | iter = parent->seeds.upper_bound(_pos); |
| 48 | --iter; |
| 49 | current_state = iter->second; |
| 50 | current_val = rand_r(¤t_state); |
| 51 | pos = iter->first; |
| 52 | ++iter; |
| 53 | } |
| 54 | while (pos < _pos) ++(*this); |
| 55 | } |
| 56 | |
| 57 | void seek_to_first() { |
| 58 | seek_to(0); |
| 59 | } |
| 60 | Iterator &operator++() { |
| 61 | ++pos; |
| 62 | if (iter != parent->seeds.end() && pos >= iter->first) { |
| 63 | ceph_assert(pos == iter->first); |
| 64 | current_state = iter->second; |
| 65 | ++iter; |
| 66 | } |
| 67 | current_val = rand_r(¤t_state); |
| 68 | return *this; |
| 69 | } |
| 70 | bool valid() { |
| 71 | return pos < parent->size(); |
| 72 | } |
| 73 | friend class ObjectContents; |
| 74 | }; |
| 75 | |
| 76 | ObjectContents() : _size(0), _exists(false) { |
| 77 | seeds[0] = 0; |