Squashed 'src/nudb/' content from commit 00adc6a

git-subtree-dir: src/nudb
git-subtree-split: 00adc6a4f16679a376f40c967f77dfa544c179c1
This commit is contained in:
Vinnie Falco
2016-09-29 19:24:12 -04:00
commit 79159ffd87
113 changed files with 15806 additions and 0 deletions

17
examples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
# Part of nudb
GroupSources (include/nudb nudb)
GroupSources (extras/nudb extras)
GroupSources (examples/ "/")
add_executable (example
${NUDB_INCLUDES}
${EXTRAS_INCLUDES}
example.cpp
)
if (WIN32)
target_link_libraries (example ${Boost_LIBRARIES})
else ()
target_link_libraries (example ${Boost_LIBRARIES} rt Threads::Threads)
endif ()

12
examples/Jamfile Normal file
View File

@@ -0,0 +1,12 @@
#
# Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
import os ;
exe example :
example.cpp
;

46
examples/example.cpp Normal file
View File

@@ -0,0 +1,46 @@
//
// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <nudb/nudb.hpp>
#include <cstddef>
#include <cstdint>
int main()
{
using namespace nudb;
std::size_t constexpr N = 1000;
using key_type = std::uint32_t;
error_code ec;
auto const dat_path = "db.dat";
auto const key_path = "db.key";
auto const log_path = "db.log";
create<xxhasher>(
dat_path, key_path, log_path,
1,
make_salt(),
sizeof(key_type),
block_size("."),
0.5f,
ec);
store db;
db.open(dat_path, key_path, log_path, ec);
char data = 0;
// Insert
for(key_type i = 0; i < N; ++i)
db.insert(&i, &data, sizeof(data), ec);
// Fetch
for(key_type i = 0; i < N; ++i)
db.fetch(&i,
[&](void const* buffer, std::size_t size)
{
// do something with buffer, size
}, ec);
db.close(ec);
erase_file(dat_path);
erase_file(key_path);
erase_file(log_path);
}