├── doc
├── tk-icon.png
├── ilove-logo.png
└── prism.css
├── tkrzw.pc.in
├── example
├── helloworld.cc
├── cachedbm_ex1.cc
├── tinydbm_ex1.cc
├── memindex_ex1.cc
├── hashdbm_ex1.cc
├── babydbm_ex1.cc
├── stdtreedbm_ex1.cc
├── langc_ex1.c
├── skipdbm_ex1.cc
├── treedbm_ex1.cc
├── sharddbm_ex1.cc
├── polydbm_ex1.cc
├── hashdbm_ex3.cc
├── skipdbm_ex3.cc
├── polyindex_ex1.cc
├── ulogrestore.cc
├── langc_ex3.c
├── accesscounter.cc
├── stdtreedbm_ex2.cc
├── babydbm_ex2.cc
├── langc_ex2.c
├── tinydbm_ex2.cc
├── struct_ex1.cc
├── asyncdbm_ex1.cc
├── treedbm_ex3.cc
├── invindex_ex1.cc
├── treedbm_ex2.cc
├── hashdbm_ex2.cc
├── VCMakefile
├── skipdbm_ex2.cc
├── Makefile
├── fileindex_ex1.cc
├── transfer.cc
├── treedbm_ex4.cc
└── stdindex_ex1.cc
├── CONTRIBUTING.md
├── tkrzw_dbm.cc
├── README
├── Doxyfile
├── tkrzw_sys_util_posix.h
├── tkrzw_file_std_test.cc
├── .github
└── workflows
│ └── build_and_test.yml
├── tkrzw_dbm_tiny_test.cc
├── tkrzw_dbm_tree_impl.cc
├── tkrzw_file_poly_test.cc
├── tkrzw_compress_test.cc
├── tkrzw_logger_test.cc
├── tkrzw_build_util.cc
├── tkrzw_dbm_tree_impl.h
├── doxy-overview.h
├── tkrzw_dbm_tree_impl_test.cc
├── tkrzw_time_util.h
├── tkrzw_dbm_std_test.cc
├── tkrzw_file_poly.cc
└── tkrzw_file_mmap_test.cc
/doc/tk-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/estraier/tkrzw/HEAD/doc/tk-icon.png
--------------------------------------------------------------------------------
/doc/ilove-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/estraier/tkrzw/HEAD/doc/ilove-logo.png
--------------------------------------------------------------------------------
/tkrzw.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | datarootdir = @datarootdir@
4 | bindir=@bindir@
5 | libdir=@libdir@
6 | libexecdir=@libexecdir@
7 | includedir=@includedir@
8 | datadir=@datadir@
9 |
10 | Name: Tkrzw
11 | Description: an implementation of DBM
12 | Version: @PACKAGE_VERSION@
13 | Libs: -L${libdir} -ltkrzw @LIBS@
14 | Cflags: -I${includedir}
15 |
--------------------------------------------------------------------------------
/example/helloworld.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Simplest example code of an Tkrzw application
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_hash.h"
15 |
16 | int main(int argc, char** argv) {
17 | tkrzw::HashDBM dbm;
18 | dbm.Open("casket.tkh", true).OrDie();
19 | dbm.Set("hello", "world").OrDie();
20 | std::cout << dbm.GetSimple("hello") << std::endl;
21 | dbm.Close().OrDie();
22 | return 0;
23 | }
24 |
25 | // END OF FILE
26 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google/conduct/).
29 |
--------------------------------------------------------------------------------
/tkrzw_dbm.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Datatabase manager interface
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_sys_config.h"
15 |
16 | #include "tkrzw_dbm.h"
17 | #include "tkrzw_file_util.h"
18 | #include "tkrzw_lib_common.h"
19 | #include "tkrzw_str_util.h"
20 |
21 | namespace tkrzw {
22 |
23 | const std::string_view DBM::ANY_DATA("\x00\xBA\xBE\x02\x11", 5);
24 |
25 | const std::string_view DBM::RecordProcessor::NOOP("\x00\xBE\xEF\x02\x11", 5);
26 |
27 | const std::string_view DBM::RecordProcessor::REMOVE("\x00\xDE\xAD\x02\x11", 5);
28 |
29 | DBM::FileProcessorCopyFileData::FileProcessorCopyFileData(
30 | Status* status, const std::string dest_path)
31 | : status_(status), dest_path_(dest_path) {}
32 |
33 | void DBM::FileProcessorCopyFileData::Process(const std::string& path) {
34 | *status_ = tkrzw::CopyFileData(path, dest_path_);
35 | }
36 |
37 | } // namespace tkrzw
38 |
39 | // END OF FILE
40 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | ================================================================================
2 | Tkrzw: a set of implementations of DBM
3 | ================================================================================
4 |
5 | Please read the following documents.
6 |
7 | COPYING - license
8 | CONTRIBUTING.md - how to contribute
9 | doc/index.xhtml - main document
10 | (the same as https://dbmx.net/tkrzw/)
11 |
12 | Contents of the directory tree are below.
13 |
14 | ./ - source code
15 | ./example/ - sample code for tutorial
16 |
17 | Tkrzw is available on UNIX-like systems (Linux, Mac OS, FreeBSD, Solaris etc)
18 | and Windows.
19 |
20 | On Unix-like systems, GCC 7.3 or later version is required to build the
21 | library. You can also use CLang, whose command interface is compatible with
22 | GCC. GNU make and other standard tools are also required.
23 | Then, run these commands. The files are installed under "/usr/local".
24 |
25 | ./configure --enable-opt-native --enable-most-features
26 | make
27 | make check
28 | sudo make install
29 |
30 | On some UNIX-like systems including FreeBSD and Solaris, "make" defaults to
31 | bsdmake or other non-GNU make, so you might need to replace "make" with
32 | "gmake" in the above instructions.
33 |
34 | On Windows, Visual Studio 2019 and its C++ components are required.
35 | Open the "x86 Native Tools Command Prompt" and then run the following
36 | commands. The files are installed under "C:\Program Files\tkrzw".
37 |
38 | nmake -f VCMakefile
39 | nmake -f VCMakefile check
40 | nmake -f VCMakefile install (run this as Administrator)
41 |
42 | Thanks.
43 |
44 | == END OF FILE ==
45 |
--------------------------------------------------------------------------------
/example/cachedbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the on-memory cache database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_cache.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | // No need to call the Open and Close methods.
23 | // The capacity is set with the constructor.
24 | constexpr int64_t cap_num_rec = 1000;
25 | constexpr int64_t cap_mem_size = cap_num_rec * 100;
26 | CacheDBM dbm(cap_num_rec, cap_mem_size);
27 |
28 | // Stores records.
29 | for (int32_t i = 0; i < 2000; i++) {
30 | dbm.Set(ToString(i), ToString(i));
31 | }
32 |
33 | // Check the number of records.
34 | std::cout << "count: " << dbm.CountSimple() << std::endl;
35 |
36 | // Recent records should be alive.
37 | for (int32_t i = 1990; i < 2000; i++) {
38 | std::cout << dbm.GetSimple(ToString(i), "*") << std::endl;
39 | }
40 |
41 | return 0;
42 | }
43 |
44 | // END OF FILE
45 |
--------------------------------------------------------------------------------
/example/tinydbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the on-memory hash database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_tiny.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | // No need to call the Open and Close methods.
23 | TinyDBM dbm;
24 |
25 | // Stores records.
26 | dbm.Set("foo", "hop");
27 | dbm.Set("bar", "step");
28 | dbm.Set("baz", "jump");
29 |
30 | // Retrieves records.
31 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
32 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
33 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
34 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
35 |
36 | // Traverses records.
37 | std::unique_ptr iter = dbm.MakeIterator();
38 | iter->First();
39 | std::string key, value;
40 | while (iter->Get(&key, &value) == Status::SUCCESS) {
41 | std::cout << key << ":" << value << std::endl;
42 | iter->Next();
43 | }
44 |
45 | return 0;
46 | }
47 |
48 | // END OF FILE
49 |
--------------------------------------------------------------------------------
/example/memindex_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for typical usage of the on-memory secondary index
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_cmd_util.h"
15 | #include "tkrzw_dbm_hash.h"
16 | #include "tkrzw_index.h"
17 | #include "tkrzw_str_util.h"
18 |
19 | // All symbols of Tkrzw are under the namespace "tkrzw".
20 | using namespace tkrzw;
21 |
22 | // Main routine.
23 | int main(int argc, char** argv) {
24 | // Prepare an index for divisions and their members.
25 | MemIndex index;
26 |
27 | // Adds records.
28 | for (int32_t i = 0; i < 100; i++) {
29 | // The key don't have to be unique.
30 | const std::string key = ToString(i / 10);
31 | // The value must be unique because it is derived from the primary key of the main DB.
32 | const std::string value = ToString(i);
33 | // Adds a pair of key-value.
34 | index.Add(key, value);
35 | }
36 |
37 | // Makes an iterator.
38 | auto it = index.MakeIterator();
39 | // Jumps to the first record.
40 | it->First();
41 | // Shows all records.
42 | std::string key, value;
43 | while (it->Get(&key, &value)) {
44 | std::cout << key << ":" << value << std::endl;
45 | it->Next();
46 | }
47 |
48 | return 0;
49 | }
50 |
51 | // END OF FILE
52 |
--------------------------------------------------------------------------------
/example/hashdbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the hash database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_hash.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | HashDBM dbm;
23 |
24 | // Opens a new database.
25 | dbm.Open("casket.tkh", true);
26 |
27 | // Stores records.
28 | dbm.Set("foo", "hop");
29 | dbm.Set("bar", "step");
30 | dbm.Set("baz", "jump");
31 |
32 | // Retrieves records.
33 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
34 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
35 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
36 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
37 |
38 | // Traverses records.
39 | std::unique_ptr iter = dbm.MakeIterator();
40 | iter->First();
41 | std::string key, value;
42 | while (iter->Get(&key, &value) == Status::SUCCESS) {
43 | std::cout << key << ":" << value << std::endl;
44 | iter->Next();
45 | }
46 |
47 | // Closes the database.
48 | dbm.Close();
49 |
50 | return 0;
51 | }
52 |
53 | // END OF FILE
54 |
--------------------------------------------------------------------------------
/example/babydbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the on-memory tree database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_baby.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | // No need to call the Open and Close methods.
23 | BabyDBM dbm;
24 |
25 | // Stores records.
26 | dbm.Set("foo", "hop");
27 | dbm.Set("bar", "step");
28 | dbm.Set("baz", "jump");
29 |
30 | // Retrieves records.
31 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
32 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
33 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
34 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
35 |
36 | // Find records by forward matching with "ba".
37 | std::unique_ptr iter = dbm.MakeIterator();
38 | iter->Jump("ba");
39 | std::string key, value;
40 | while (iter->Get(&key, &value) == Status::SUCCESS) {
41 | if (!StrBeginsWith(key, "ba")) break;
42 | std::cout << key << ":" << value << std::endl;
43 | iter->Next();
44 | }
45 |
46 | return 0;
47 | }
48 |
49 | // END OF FILE
50 |
--------------------------------------------------------------------------------
/example/stdtreedbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the STL on-memory tree database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_std.h"
15 | #include "tkrzw_str_util.h"
16 |
17 | // Main routine.
18 | int main(int argc, char** argv) {
19 | // All symbols of Tkrzw are under the namespace "tkrzw".
20 | using namespace tkrzw;
21 |
22 | // Creates the database manager.
23 | // No need to call the Open and Close methods.
24 | StdTreeDBM dbm;
25 |
26 | // Stores records
27 | dbm.Set("foo", "hop");
28 | dbm.Set("bar", "step");
29 | dbm.Set("baz", "jump");
30 |
31 | // Retrieves records.
32 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
33 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
34 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
35 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
36 |
37 | // Find records by forward matching with "ba".
38 | std::unique_ptr iter = dbm.MakeIterator();
39 | iter->Jump("ba");
40 | std::string key, value;
41 | while (iter->Get(&key, &value) == Status::SUCCESS) {
42 | if (!StrBeginsWith(key, "ba")) break;
43 | std::cout << key << ":" << value << std::endl;
44 | iter->Next();
45 | }
46 |
47 | return 0;
48 | }
49 |
50 | // END OF FILE
51 |
--------------------------------------------------------------------------------
/example/langc_ex1.c:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for the C language interface
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include
15 | #include "tkrzw_langc.h"
16 |
17 | // Main routine.
18 | int main(int argc, char** argv) {
19 | // Opens the database file.
20 | TkrzwDBM* dbm = tkrzw_dbm_open(
21 | "casket.tkh", true, "truncate=true,num_buckets=100");
22 |
23 | // Stores records.
24 | tkrzw_dbm_set(dbm, "foo", -1, "hop", -1, true);
25 | tkrzw_dbm_set(dbm, "bar", -1, "step", -1, true);
26 | tkrzw_dbm_set(dbm, "baz", -1, "jump", -1, true);
27 |
28 | // Retrieves a record.
29 | char* value_ptr = tkrzw_dbm_get(dbm, "foo", -1, NULL);
30 | if (value_ptr) {
31 | puts(value_ptr);
32 | free(value_ptr);
33 | }
34 |
35 | // Traverses records.
36 | TkrzwDBMIter* iter = tkrzw_dbm_make_iterator(dbm);
37 | tkrzw_dbm_iter_first(iter);
38 | while (true) {
39 | char* key_ptr = NULL;
40 | if (!tkrzw_dbm_iter_get(iter, &key_ptr, NULL, &value_ptr, NULL)) {
41 | break;
42 | }
43 | printf("%s:%s\n", key_ptr, value_ptr);
44 | free(key_ptr);
45 | free(value_ptr);
46 | tkrzw_dbm_iter_next(iter);
47 | }
48 | tkrzw_dbm_iter_free(iter);
49 |
50 | // Closes the database file.
51 | tkrzw_dbm_close(dbm);
52 |
53 | return 0;
54 | }
55 |
56 | // END OF FILE
57 |
--------------------------------------------------------------------------------
/example/skipdbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the skip database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_skip.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | SkipDBM dbm;
23 |
24 | // Opens a new database.
25 | dbm.Open("casket.tks", true);
26 |
27 | // Stores records.
28 | dbm.Set("foo", "hop");
29 | dbm.Set("bar", "step");
30 | dbm.Set("baz", "jump");
31 |
32 | // Synchronizes the database.
33 | dbm.Synchronize(false);
34 |
35 | // Retrieves records.
36 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
37 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
38 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
39 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
40 |
41 | // Traverses records.
42 | std::unique_ptr iter = dbm.MakeIterator();
43 | iter->First();
44 | std::string key, value;
45 | while (iter->Get(&key, &value) == Status::SUCCESS) {
46 | std::cout << key << ":" << value << std::endl;
47 | iter->Next();
48 | }
49 |
50 | // Closes the database.
51 | dbm.Close();
52 |
53 | return 0;
54 | }
55 |
56 | // END OF FILE
57 |
--------------------------------------------------------------------------------
/example/treedbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the tree database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_tree.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | TreeDBM dbm;
23 |
24 | // Opens a new database.
25 | dbm.Open("casket.tkt", true);
26 |
27 | // Stores records.
28 | dbm.Set("foo", "hop");
29 | dbm.Set("bar", "step");
30 | dbm.Set("baz", "jump");
31 |
32 | // Retrieves records.
33 | std::cout << dbm.GetSimple("foo", "*") << std::endl;
34 | std::cout << dbm.GetSimple("bar", "*") << std::endl;
35 | std::cout << dbm.GetSimple("baz", "*") << std::endl;
36 | std::cout << dbm.GetSimple("outlier", "*") << std::endl;
37 |
38 | // Find records by forward matching with "ba".
39 | std::unique_ptr iter = dbm.MakeIterator();
40 | iter->Jump("ba");
41 | std::string key, value;
42 | while (iter->Get(&key, &value) == Status::SUCCESS) {
43 | if (!StrBeginsWith(key, "ba")) break;
44 | std::cout << key << ":" << value << std::endl;
45 | iter->Next();
46 | }
47 |
48 | // Closes the database.
49 | dbm.Close();
50 |
51 | return 0;
52 | }
53 |
54 | // END OF FILE
55 |
--------------------------------------------------------------------------------
/example/sharddbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the sharding database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_shard.h"
15 | #include "tkrzw_str_util.h"
16 |
17 | // Main routine.
18 | int main(int argc, char** argv) {
19 | // All symbols of Tkrzw are under the namespace "tkrzw".
20 | using namespace tkrzw;
21 |
22 | // Creates the database manager.
23 | ShardDBM dbm;
24 |
25 | // Opens a new database.
26 | const std::map open_params = {
27 | {"num_shards", "10"},
28 | {"dbm", "TreeDBM"}, {"key_comparator", "DecimalKeyComparator"},
29 | };
30 | dbm.OpenAdvanced("casket", true, File::OPEN_TRUNCATE, open_params).OrDie();
31 |
32 | // Stores records.
33 | for (int32_t i = 1; i <= 100; i++) {
34 | const std::string key = ToString(i);
35 | const std::string value = ToString(i * i);
36 | dbm.Set(key, value).OrDie();
37 | }
38 |
39 | // Retrieve records whose keys are 50 or more.
40 | auto iter = dbm.MakeIterator();
41 | iter->Jump("50");
42 | std::string key, value;
43 | while (iter->Get(&key, &value).IsOK()) {
44 | std::cout << key << ":" << value << std::endl;
45 | iter->Next();
46 | }
47 |
48 | // Closes the database.
49 | dbm.Close().OrDie();
50 |
51 | return 0;
52 | }
53 |
54 | // END OF FILE
55 |
--------------------------------------------------------------------------------
/Doxyfile:
--------------------------------------------------------------------------------
1 | # Doxygen configuration for Tkrzw
2 |
3 | # General configuration options
4 | PROJECT_NAME = "Tkrzw"
5 | OUTPUT_LANGUAGE = English
6 | EXTRACT_ALL = NO
7 | EXTRACT_PRIVATE = NO
8 | EXTRACT_STATIC = NO
9 | REPEAT_BRIEF = YES
10 | ALWAYS_DETAILED_SEC = YES
11 | SHOW_INCLUDE_FILES = YES
12 | VERBATIM_HEADERS = NO
13 | JAVADOC_AUTOBRIEF = YES
14 | SORT_MEMBER_DOCS = NO
15 | INLINE_INFO = NO
16 | OPTIMIZE_OUTPUT_FOR_C = NO
17 | OPTIMIZE_OUTPUT_JAVA = NO
18 | SHOW_USED_FILES = NO
19 | QUIET = YES
20 | WARNINGS = YES
21 | SEARCHENGINE = NO
22 |
23 | # Configuration options related to the input files
24 | INPUT = .
25 | FILE_PATTERNS = doxy-overview.h tkrzw_lib_common.h tkrzw_str_util.h tkrzw_hash_util.h tkrzw_time_util.h tkrzw_thread_util.h tkrzw_logger.h tkrzw_compress.h tkrzw_containers.h tkrzw_key_comparators.h tkrzw_file_util.h tkrzw_file.h tkrzw_file_std.h tkrzw_file_mmap.h tkrzw_file_pos.h tkrzw_file_poly.h tkrzw_message_queue.h tkrzw_dbm.h tkrzw_dbm_ulog.h tkrzw_dbm_common_impl.h tkrzw_dbm_hash_impl.h tkrzw_dbm_hash.h tkrzw_dbm_tree_impl.h tkrzw_dbm_tree.h tkrzw_dbm_skip_impl.h tkrzw_dbm_skip.h tkrzw_dbm_tiny.h tkrzw_dbm_baby.h tkrzw_dbm_cache.h tkrzw_dbm_std.h tkrzw_dbm_poly.h tkrzw_dbm_shard.h tkrzw_dbm_async.h tkrzw_index.h tkrzw_cmd_util.h tkrzw_langc.h
26 | RECURSIVE = NO
27 |
28 | # Configuration options related to the alphabetical index
29 | ALPHABETICAL_INDEX = YES
30 |
31 | # Configuration options related to the HTML output
32 | GENERATE_HTML = YES
33 | HTML_OUTPUT = api-doc
34 | HTML_FILE_EXTENSION = .html
35 | GENERATE_TREEVIEW = NO
36 | TREEVIEW_WIDTH = 250
37 |
38 | # Configuration options related to the LaTeX output
39 | GENERATE_LATEX = NO
40 | LATEX_OUTPUT = latex
41 |
42 | # Configuration options related to the man page output
43 | GENERATE_MAN = NO
44 | MAN_OUTPUT = .
45 | MAN_EXTENSION = .3
46 |
47 | # Configuration options related to the dot tool
48 | HAVE_DOT = NO
49 | CLASS_GRAPH = NO
50 | COLLABORATION_GRAPH = NO
51 | INCLUDE_GRAPH = NO
52 | INCLUDED_BY_GRAPH = NO
53 | GRAPHICAL_HIERARCHY = YES
54 | GENERATE_LEGEND = NO
55 | DOT_CLEANUP = YES
56 |
57 | # END OF FILE
58 |
--------------------------------------------------------------------------------
/example/polydbm_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for basic usage of the polymorphic database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_dbm_poly.h"
15 |
16 | // Main routine.
17 | int main(int argc, char** argv) {
18 | // All symbols of Tkrzw are under the namespace "tkrzw".
19 | using namespace tkrzw;
20 |
21 | // Creates the database manager.
22 | PolyDBM dbm;
23 |
24 | // Opens a new database.
25 | const std::map open_params = {
26 | {"update_mode", "UPDATE_APPENDING"},
27 | {"max_page_size", "1000"}, {"max_branches", "128"},
28 | {"key_comparator", "DecimalKeyComparator"},
29 | };
30 | dbm.OpenAdvanced("casket.tkt", true, File::OPEN_TRUNCATE, open_params).OrDie();
31 |
32 | // Stores records.
33 | dbm.Set("1", "one").OrDie();
34 | dbm.Set("2", "two").OrDie();
35 | dbm.Set("3", "three").OrDie();
36 |
37 | // Rebuild the database.
38 | const std::map rebuild_params = {
39 | {"update_mode", "UPDATE_IN_PLACE"},
40 | {"max_page_size", "4080"}, {"max_branches", "256"},
41 | };
42 | dbm.RebuildAdvanced(rebuild_params).OrDie();
43 |
44 | // Retrieves records.
45 | std::cout << dbm.GetSimple("1", "*") << std::endl;
46 | std::cout << dbm.GetSimple("2", "*") << std::endl;
47 | std::cout << dbm.GetSimple("3", "*") << std::endl;
48 | std::cout << dbm.GetSimple("4", "*") << std::endl;
49 |
50 | // Closes the database.
51 | dbm.Close().OrDie();
52 |
53 | return 0;
54 | }
55 |
56 | // END OF FILE
57 |
--------------------------------------------------------------------------------
/example/hashdbm_ex3.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for advanced operations of the hash database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_cmd_util.h"
15 | #include "tkrzw_dbm_hash.h"
16 | #include "tkrzw_str_util.h"
17 |
18 | // Main routine.
19 | int main(int argc, char** argv) {
20 | // All symbols of Tkrzw are under the namespace "tkrzw".
21 | using namespace tkrzw;
22 |
23 | // Creates the database manager.
24 | HashDBM dbm;
25 |
26 | // Opens a new database,
27 | dbm.Open("casket.tkh", true, File::OPEN_TRUNCATE);
28 |
29 | // Record processor to count events.
30 | class Counter : public DBM::RecordProcessor {
31 | public:
32 | // Update an existing record.
33 | virtual std::string_view ProcessFull(std::string_view key, std::string_view value) {
34 | new_value_ = ToString(StrToInt(value) + 1);
35 | return new_value_;
36 | }
37 | // Register a new record.
38 | virtual std::string_view ProcessEmpty(std::string_view key) {
39 | return "1";
40 | }
41 | private:
42 | std::string new_value_;
43 | };
44 |
45 | // Procedure to count up an event.
46 | // DBM::IncrementSimple does the same job.
47 | const auto CountUp = [&](std::string_view name) {
48 | Counter counter;
49 | dbm.Process(name, &counter, true);
50 | };
51 |
52 | // Counts up events.
53 | CountUp("foo");
54 | CountUp("foo");
55 | CountUp("bar");
56 |
57 | // Reports counts.
58 | std::cout << dbm.GetSimple("foo", "0") << std::endl;
59 | std::cout << dbm.GetSimple("bar", "0") << std::endl;
60 | std::cout << dbm.GetSimple("baz", "0") << std::endl;
61 |
62 | // Closes the database.
63 | dbm.Close();
64 |
65 | return 0;
66 | }
67 |
68 | // END OF FILE
69 |
--------------------------------------------------------------------------------
/example/skipdbm_ex3.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for advanced operations of the skip database
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include "tkrzw_cmd_util.h"
15 | #include "tkrzw_dbm_skip.h"
16 | #include "tkrzw_str_util.h"
17 |
18 | // Main routine.
19 | int main(int argc, char** argv) {
20 | // All symbols of Tkrzw are under the namespace "tkrzw".
21 | using namespace tkrzw;
22 |
23 | // Creates the database manager.
24 | SkipDBM dbm;
25 |
26 | // Opens a new database,
27 | Status status = dbm.Open("casket.tks", true, File::OPEN_TRUNCATE);
28 |
29 | // Adds records.
30 | // Duplicated keys are allowed.
31 | dbm.Set("Japan", "Tokyo");
32 | dbm.Set("Japan", "Osaka");
33 | dbm.Set("France", "Paris");
34 | dbm.Set("China", "Beijing");
35 |
36 | // Synchronizes the database.
37 | // This makes new records visible.
38 | dbm.Synchronize(false);
39 |
40 | // Prints all records.
41 | PrintL("-- Original Records --");
42 | PrintDBMRecordsInTSV(&dbm);
43 |
44 | // Adds more records.
45 | dbm.Set("Japan", "Nagoya");
46 | dbm.Set("China", "Shanghai");
47 |
48 | // Removes a record.
49 | dbm.Remove("France");
50 |
51 | // Synchronizes the database.
52 | // This makes the updates visible.
53 | dbm.Synchronize(false);
54 |
55 | // Prints all records.
56 | PrintL("-- Records After Updates --");
57 | PrintDBMRecordsInTSV(&dbm);
58 |
59 | // Synchronizes the database with a reducer to deduplicate records.
60 | dbm.SynchronizeAdvanced(false, nullptr, SkipDBM::ReduceToFirst);
61 |
62 | // Prints all records.
63 | PrintL("-- Records After Deduplication --");
64 | PrintDBMRecordsInTSV(&dbm);
65 |
66 | // Closes the database.
67 | status = dbm.Close();
68 |
69 | return 0;
70 | }
71 |
72 | // END OF FILE
73 |
--------------------------------------------------------------------------------
/example/polyindex_ex1.cc:
--------------------------------------------------------------------------------
1 | /*************************************************************************************************
2 | * Example for typical usage of the polymorphic secondary index
3 | *
4 | * Copyright 2020 Google LLC
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 | * except in compliance with the License. You may obtain a copy of the License at
7 | * https://www.apache.org/licenses/LICENSE-2.0
8 | * Unless required by applicable law or agreed to in writing, software distributed under the
9 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10 | * either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | *************************************************************************************************/
13 |
14 | #include