@@ -53,43 +53,26 @@ size_t match_extra_code(const table::Code* extra_code, size_t depth,
53
53
54
54
} // namespace dictionary
55
55
56
- DictEntryIterator::DictEntryIterator ()
57
- : Base(), table_(NULL ), entry_(), entry_count_(0 ) {
58
- }
59
-
60
- DictEntryIterator::DictEntryIterator (const DictEntryIterator& other)
61
- : Base(other), table_(other.table_), entry_(other.entry_),
62
- entry_count_ (other.entry_count_) {
63
- }
64
-
65
- DictEntryIterator& DictEntryIterator::operator = (DictEntryIterator& other) {
66
- DLOG (INFO) << " swapping iterator contents." ;
67
- swap (other);
68
- table_ = other.table_ ;
69
- entry_ = other.entry_ ;
70
- entry_count_ = other.entry_count_ ;
71
- return *this ;
72
- }
73
-
74
- bool DictEntryIterator::exhausted () const {
75
- return empty ();
76
- }
77
-
78
56
void DictEntryIterator::AddChunk (dictionary::Chunk&& chunk, Table* table) {
79
- push_back (std::move (chunk));
57
+ chunks_. push_back (std::move (chunk));
80
58
entry_count_ += chunk.size ;
81
59
table_ = table;
82
60
}
83
61
84
62
void DictEntryIterator::Sort () {
85
- sort (dictionary::compare_chunk_by_head_element);
63
+ // partial-sort remaining chunks, move best match to chunk_index_
64
+ std::partial_sort (
65
+ chunks_.begin () + chunk_index_,
66
+ chunks_.begin () + chunk_index_ + 1 ,
67
+ chunks_.end (),
68
+ dictionary::compare_chunk_by_head_element);
86
69
}
87
70
88
71
void DictEntryIterator::PrepareEntry () {
89
- if (empty () || !table_) {
72
+ if (exhausted () || !table_) {
90
73
return ;
91
74
}
92
- const auto & chunk (front () );
75
+ const auto & chunk (chunks_[chunk_index_] );
93
76
entry_ = New<DictEntry>();
94
77
const auto & e (chunk.entries [chunk.cursor ]);
95
78
DLOG (INFO) << " creating temporary dict entry '"
@@ -105,7 +88,7 @@ void DictEntryIterator::PrepareEntry() {
105
88
}
106
89
107
90
an<DictEntry> DictEntryIterator::Peek () {
108
- while (!entry_ && !empty ()) {
91
+ while (!entry_ && !exhausted ()) {
109
92
PrepareEntry ();
110
93
if (filter_ && !filter_ (entry_)) {
111
94
Next ();
@@ -116,30 +99,30 @@ an<DictEntry> DictEntryIterator::Peek() {
116
99
117
100
bool DictEntryIterator::Next () {
118
101
entry_.reset ();
119
- if (empty ()) {
102
+ if (exhausted ()) {
120
103
return false ;
121
104
}
122
- auto & chunk (front () );
105
+ auto & chunk (chunks_[chunk_index_] );
123
106
if (++chunk.cursor >= chunk.size ) {
124
- pop_front () ;
107
+ ++chunk_index_ ;
125
108
}
126
109
else {
127
- // reorder chunks since front() has got a new head element
110
+ // reorder chunks since the current chunk has got a new head element
128
111
Sort ();
129
112
}
130
- return !empty ();
113
+ return !exhausted ();
131
114
}
132
115
133
116
bool DictEntryIterator::Skip (size_t num_entries) {
134
117
while (num_entries > 0 ) {
135
- if (empty ()) return false ;
136
- auto & chunk (front () );
118
+ if (exhausted ()) return false ;
119
+ auto & chunk (chunks_[chunk_index_] );
137
120
if (chunk.cursor + num_entries < chunk.size ) {
138
121
chunk.cursor += num_entries;
139
122
return true ;
140
123
}
141
124
num_entries -= (chunk.size - chunk.cursor );
142
- pop_front () ;
125
+ ++chunk_index_ ;
143
126
}
144
127
return true ;
145
128
}
0 commit comments