susumu.yata
null+****@clear*****
Mon Feb 9 13:50:25 JST 2015
susumu.yata 2015-02-09 13:50:25 +0900 (Mon, 09 Feb 2015) New Revision: c5c9bc6aa84734126940f088da1314af389f82c3 https://github.com/groonga/grnxx/commit/c5c9bc6aa84734126940f088da1314af389f82c3 Message: Put index type constants in the C global namespace. (#144) Modified files: benchmark/benchmark_foreign_key.cpp include/grnxx/constants.h include/grnxx/index.hpp lib/grnxx/impl/index.cpp test/test_column.cpp test/test_index.cpp Modified: benchmark/benchmark_foreign_key.cpp (+2 -2) =================================================================== --- benchmark/benchmark_foreign_key.cpp 2015-02-09 13:42:23 +0900 (53468da) +++ benchmark/benchmark_foreign_key.cpp 2015-02-09 13:50:25 +0900 (94a8feb) @@ -119,7 +119,7 @@ void benchmark_indirect_build() try { auto db = grnxx::open_db(""); auto to_table = db->create_table("Values"); auto column = to_table->create_column("Value", GRNXX_TEXT); - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); to_table->set_key_column("Value"); for (size_t j = 0; j < VALUES_SIZE; ++j) { to_table->insert_row(values[j]); @@ -154,7 +154,7 @@ void benchmark_sequential_build() try { auto db = grnxx::open_db(""); auto to_table = db->create_table("Values"); auto value_column = to_table->create_column("Value", GRNXX_TEXT); - value_column->create_index("Index", grnxx::TREE_INDEX); + value_column->create_index("Index", GRNXX_TREE_INDEX); to_table->set_key_column("Value"); auto from_table = db->create_table("Refs"); grnxx::ColumnOptions options; Modified: include/grnxx/constants.h (+7 -0) =================================================================== --- include/grnxx/constants.h 2015-02-09 13:42:23 +0900 (982cb21) +++ include/grnxx/constants.h 2015-02-09 13:50:25 +0900 (164ae27) @@ -37,6 +37,13 @@ typedef enum { GRNXX_REVERSE_ORDER } grnxx_order_type; +typedef enum { + // Tree indexes support range search. + GRNXX_TREE_INDEX, + // Hash indexes support exact match search. + GRNXX_HASH_INDEX +} grnxx_index_type; + #ifdef __cplusplus } // extern "C" #endif // __cplusplus Modified: include/grnxx/index.hpp (+2 -6) =================================================================== --- include/grnxx/index.hpp 2015-02-09 13:42:23 +0900 (95494d2) +++ include/grnxx/index.hpp 2015-02-09 13:50:25 +0900 (602c459) @@ -3,6 +3,7 @@ #include <memory> +#include "grnxx/constants.h" #include "grnxx/cursor.hpp" #include "grnxx/data_types.hpp" #include "grnxx/index.hpp" @@ -59,12 +60,7 @@ class IndexRange { EndPoint upper_bound_; }; -enum IndexType { - // TODO: Tree indexes support range search. - TREE_INDEX, - // TODO: Hash indexes support exact match search. - HASH_INDEX -}; +using IndexType = grnxx_index_type; struct IndexOptions { }; Modified: lib/grnxx/impl/index.cpp (+8 -8) =================================================================== --- lib/grnxx/impl/index.cpp 2015-02-09 13:42:23 +0900 (e141bec) +++ lib/grnxx/impl/index.cpp 2015-02-09 13:50:25 +0900 (500685f) @@ -314,7 +314,7 @@ class TreeIndex<Int> : public Index { ~TreeIndex() = default; IndexType type() const { - return TREE_INDEX; + return GRNXX_TREE_INDEX; } size_t num_entries() const { return num_entries_; @@ -494,7 +494,7 @@ class TreeIndex<Float> : public Index { ~TreeIndex() = default; IndexType type() const { - return TREE_INDEX; + return GRNXX_TREE_INDEX; } size_t num_entries() const { return num_entries_; @@ -675,7 +675,7 @@ class TreeIndex<Text> : public Index { ~TreeIndex() = default; IndexType type() const { - return TREE_INDEX; + return GRNXX_TREE_INDEX; } size_t num_entries() const { return num_entries_; @@ -947,7 +947,7 @@ class HashIndex<Int> : public Index { ~HashIndex() = default; IndexType type() const { - return HASH_INDEX; + return GRNXX_HASH_INDEX; } size_t num_entries() const { return num_entries_; @@ -1080,7 +1080,7 @@ class HashIndex<Float> : public Index { ~HashIndex() = default; IndexType type() const { - return HASH_INDEX; + return GRNXX_HASH_INDEX; } size_t num_entries() const { return num_entries_; @@ -1203,7 +1203,7 @@ class HashIndex<Text> : public Index { ~HashIndex() = default; IndexType type() const { - return HASH_INDEX; + return GRNXX_HASH_INDEX; } size_t num_entries() const { return num_entries_; @@ -1370,7 +1370,7 @@ Index *Index::create(ColumnBase *column, IndexType type, const IndexOptions &options) try { switch (type) { - case TREE_INDEX: { + case GRNXX_TREE_INDEX: { switch (column->data_type()) { case GRNXX_BOOL: { throw "Not supported yet"; // TODO @@ -1397,7 +1397,7 @@ Index *Index::create(ColumnBase *column, } } } - case HASH_INDEX: { + case GRNXX_HASH_INDEX: { switch (column->data_type()) { case GRNXX_BOOL: { throw "Not supported yet"; // TODO Modified: test/test_column.cpp (+6 -6) =================================================================== --- test/test_column.cpp 2015-02-09 13:42:23 +0900 (a7c4304) +++ test/test_column.cpp 2015-02-09 13:50:25 +0900 (791e356) @@ -254,7 +254,7 @@ void test_contains_and_find_one() { // Test all the values with index if available. try { - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); for (size_t i = 0; i < NUM_ROWS; ++i) { assert(column->contains(values[i])); grnxx::Int row_id = column->find_one(values[i]); @@ -286,7 +286,7 @@ void test_contains_and_find_one() { // Test all the values with index if available. try { - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); for (size_t i = 0; i < NUM_ROWS; ++i) { if (!values[i].is_na()) { assert(column->contains(values[i])); @@ -306,7 +306,7 @@ void test_contains_and_find_one() { assert(column->contains(T::na())); assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS))); try { - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); assert(column->contains(T::na())); assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS))); column->remove_index("Index"); @@ -332,7 +332,7 @@ void test_contains_and_find_one() { // Test all the values with index if available. try { - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); for (size_t i = 0; i < NUM_ROWS; ++i) { if (!values[i].is_na()) { assert(!column->contains(values[i])); @@ -466,7 +466,7 @@ void test_contains() { assert(column->contains(grnxx::Int(789))); assert(!column->contains(grnxx::Int::na())); - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); assert(column->contains(grnxx::Int(123))); assert(column->contains(grnxx::Int(456))); assert(column->contains(grnxx::Int(789))); @@ -517,7 +517,7 @@ void test_find_one() { assert(!column->find_one(grnxx::Int(789)).is_na()); assert(column->find_one(grnxx::Int::na()).is_na()); - column->create_index("Index", grnxx::TREE_INDEX); + column->create_index("Index", GRNXX_TREE_INDEX); assert(!column->find_one(grnxx::Int(123)).is_na()); assert(!column->find_one(grnxx::Int(456)).is_na()); assert(!column->find_one(grnxx::Int(789)).is_na()); Modified: test/test_index.cpp (+16 -16) =================================================================== --- test/test_index.cpp 2015-02-09 13:42:23 +0900 (9baa268) +++ test/test_index.cpp 2015-02-09 13:50:25 +0900 (a75f6cc) @@ -36,10 +36,10 @@ void test_index() { auto column = table->create_column("Column", GRNXX_INT); // Create an index named "Index". - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); assert(index->column() == column); assert(index->name() == "Index"); - assert(index->type() == grnxx::TREE_INDEX); + assert(index->type() == GRNXX_TREE_INDEX); assert(column->num_indexes() == 1); assert(column->get_index(0) == index); @@ -73,7 +73,7 @@ void test_set_and_index() { } // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Create a cursor. auto cursor = index->find_in_range(); @@ -102,7 +102,7 @@ void test_index_and_set() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Int: [0, 100) or N/A. @@ -171,7 +171,7 @@ void test_remove() { } // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Remove even rows. size_t odd_count = total_count; @@ -213,7 +213,7 @@ void test_int_exact_match() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Int: [0, 100) or N/A. @@ -264,7 +264,7 @@ void test_float_exact_match() { auto column = table->create_column("Column", GRNXX_FLOAT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Float: [0, 1.0) or N/A. @@ -315,7 +315,7 @@ void test_text_exact_match() { auto column = table->create_column("Column", GRNXX_TEXT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Text: ["0", "256") or N/A. @@ -370,7 +370,7 @@ void test_int_range() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Int: [0, 100). @@ -423,7 +423,7 @@ void test_float_range() { auto column = table->create_column("Column", GRNXX_FLOAT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Float: [0.0, 1.0). @@ -476,7 +476,7 @@ void test_text_range() { auto column = table->create_column("Column", GRNXX_TEXT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Text: ["0", "99"]. @@ -533,7 +533,7 @@ void test_text_find_starts_with() { auto column = table->create_column("Column", GRNXX_TEXT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Text: ["0", "99"]. @@ -617,7 +617,7 @@ void test_text_find_prefixes() { auto column = table->create_column("Column", GRNXX_TEXT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Text: ["0", "99"]. @@ -670,7 +670,7 @@ void test_reverse() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Int: [0, 100). @@ -730,7 +730,7 @@ void test_offset_and_limit() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); // Generate random values. // Int: [0, 100). @@ -796,7 +796,7 @@ void test_uniqueness() { auto column = table->create_column("Column", GRNXX_INT); // Create an index. - auto index = column->create_index("Index", grnxx::TREE_INDEX); + auto index = column->create_index("Index", GRNXX_TREE_INDEX); assert(index->test_uniqueness()); grnxx::Int row_id = table->insert_row(); -------------- next part -------------- HTML����������������������������...Download