Skip to content

Commit e14072c

Browse files
authored
Optimize table iterator (swoole#4297)
* Remove Table ArrayAccess, Refactor TableIterator * Added Table::exists() * Remove row tests * refactor, add core tests
1 parent dc1377e commit e14072c

File tree

5 files changed

+128
-297
lines changed

5 files changed

+128
-297
lines changed

core-tests/src/memory/table.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using namespace swoole;
2424

2525
#include <exception>
26+
#include <map>
2627

2728
struct exception_t : public std::exception {
2829
int code;
@@ -119,6 +120,10 @@ class table_t {
119120
return table->count();
120121
}
121122

123+
Table *ptr() {
124+
return table;
125+
}
126+
122127
~table_t() {
123128
if (table) {
124129
table->destroy();
@@ -144,3 +149,25 @@ TEST(table, create) {
144149
ASSERT_TRUE(table.del("php"));
145150
ASSERT_FALSE(table.exists("php"));
146151
}
152+
153+
TEST(table, iterator) {
154+
table_t table(1024);
155+
156+
table.set("php", {"php", 1, 1.245});
157+
table.set("java", {"java", 2, 3.1415926});
158+
table.set("c++", {"c++", 3, 4.888});
159+
160+
auto _ptr = table.ptr();
161+
_ptr->rewind();
162+
auto count = 0;
163+
while (true) {
164+
_ptr->forward();
165+
auto row = _ptr->current();
166+
if (row->key_len == 0) {
167+
break;
168+
}
169+
ASSERT_TRUE(_ptr->exists(row->key, row->key_len));
170+
count++;
171+
}
172+
ASSERT_EQ(count, _ptr->count());
173+
}

0 commit comments

Comments
 (0)