├── .dntrc
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── CONTRIBUTORS.md
├── LICENSE.md
├── README.md
├── UPGRADING.md
├── bench
├── db-bench-plot.sh
├── db-bench.js
├── write-random-plot.sh
├── write-random.js
├── write-sorted-plot.sh
└── write-sorted.js
├── binding.gyp
├── chained-batch.js
├── deps
├── leveldb
│ ├── leveldb-hyper-1.0.2
│ │ ├── .tarballignore
│ │ ├── AUTHORS
│ │ ├── LICENSE
│ │ ├── Makefile.am
│ │ ├── NEWS
│ │ ├── README
│ │ ├── TODO
│ │ ├── benchmark.cc
│ │ ├── configure.ac
│ │ ├── db
│ │ │ ├── autocompact_test.cc
│ │ │ ├── builder.cc
│ │ │ ├── builder.h
│ │ │ ├── c.cc
│ │ │ ├── c_test.c
│ │ │ ├── corruption_test.cc
│ │ │ ├── db_bench.cc
│ │ │ ├── db_impl.cc
│ │ │ ├── db_impl.h
│ │ │ ├── db_iter.cc
│ │ │ ├── db_iter.h
│ │ │ ├── db_test.cc
│ │ │ ├── dbformat.cc
│ │ │ ├── dbformat.h
│ │ │ ├── dbformat_test.cc
│ │ │ ├── filename.cc
│ │ │ ├── filename.h
│ │ │ ├── filename_test.cc
│ │ │ ├── leveldb_main.cc
│ │ │ ├── log_format.h
│ │ │ ├── log_reader.cc
│ │ │ ├── log_reader.h
│ │ │ ├── log_test.cc
│ │ │ ├── log_writer.cc
│ │ │ ├── log_writer.h
│ │ │ ├── memtable.cc
│ │ │ ├── memtable.h
│ │ │ ├── repair.cc
│ │ │ ├── replay_iterator.cc
│ │ │ ├── replay_iterator.h
│ │ │ ├── skiplist.h
│ │ │ ├── skiplist_test.cc
│ │ │ ├── snapshot.h
│ │ │ ├── table_cache.cc
│ │ │ ├── table_cache.h
│ │ │ ├── version_edit.cc
│ │ │ ├── version_edit.h
│ │ │ ├── version_edit_test.cc
│ │ │ ├── version_set.cc
│ │ │ ├── version_set.h
│ │ │ ├── version_set_test.cc
│ │ │ ├── write_batch.cc
│ │ │ ├── write_batch_internal.h
│ │ │ └── write_batch_test.cc
│ │ ├── doc
│ │ │ ├── benchmark.html
│ │ │ ├── doc.css
│ │ │ ├── impl.html
│ │ │ ├── index.html
│ │ │ ├── log_format.txt
│ │ │ └── table_format.txt
│ │ ├── helpers
│ │ │ └── memenv
│ │ │ │ ├── memenv.cc
│ │ │ │ ├── memenv.h
│ │ │ │ └── memenv_test.cc
│ │ ├── hyperleveldb.upack.in
│ │ ├── hyperleveldb
│ │ │ ├── c.h
│ │ │ ├── cache.h
│ │ │ ├── comparator.h
│ │ │ ├── db.h
│ │ │ ├── env.h
│ │ │ ├── filter_policy.h
│ │ │ ├── iterator.h
│ │ │ ├── options.h
│ │ │ ├── replay_iterator.h
│ │ │ ├── slice.h
│ │ │ ├── status.h
│ │ │ ├── table.h
│ │ │ ├── table_builder.h
│ │ │ └── write_batch.h
│ │ ├── issues
│ │ │ ├── issue178_test.cc
│ │ │ └── issue200_test.cc
│ │ ├── leveldb-verify.cc
│ │ ├── libhyperleveldb.pc.in
│ │ ├── m4
│ │ │ ├── anal_warnings.m4
│ │ │ ├── anal_warnings_cxx.m4
│ │ │ └── ax_check_compile_flag.m4
│ │ ├── port
│ │ │ ├── README
│ │ │ ├── atomic_pointer.h
│ │ │ ├── port.h
│ │ │ ├── port_example.h
│ │ │ ├── port_posix.cc
│ │ │ ├── port_posix.h
│ │ │ ├── thread_annotations.h
│ │ │ └── win
│ │ │ │ └── stdint.h
│ │ ├── table
│ │ │ ├── block.cc
│ │ │ ├── block.h
│ │ │ ├── block_builder.cc
│ │ │ ├── block_builder.h
│ │ │ ├── filter_block.cc
│ │ │ ├── filter_block.h
│ │ │ ├── filter_block_test.cc
│ │ │ ├── format.cc
│ │ │ ├── format.h
│ │ │ ├── iterator.cc
│ │ │ ├── iterator_wrapper.h
│ │ │ ├── merger.cc
│ │ │ ├── merger.h
│ │ │ ├── table.cc
│ │ │ ├── table_builder.cc
│ │ │ ├── table_test.cc
│ │ │ ├── two_level_iterator.cc
│ │ │ └── two_level_iterator.h
│ │ └── util
│ │ │ ├── arena.cc
│ │ │ ├── arena.h
│ │ │ ├── arena_test.cc
│ │ │ ├── bloom.cc
│ │ │ ├── bloom_test.cc
│ │ │ ├── cache.cc
│ │ │ ├── cache_test.cc
│ │ │ ├── coding.cc
│ │ │ ├── coding.h
│ │ │ ├── coding_test.cc
│ │ │ ├── comparator.cc
│ │ │ ├── crc32c.cc
│ │ │ ├── crc32c.h
│ │ │ ├── crc32c_test.cc
│ │ │ ├── env.cc
│ │ │ ├── env_posix.cc
│ │ │ ├── env_test.cc
│ │ │ ├── filter_policy.cc
│ │ │ ├── hash.cc
│ │ │ ├── hash.h
│ │ │ ├── histogram.cc
│ │ │ ├── histogram.h
│ │ │ ├── logging.cc
│ │ │ ├── logging.h
│ │ │ ├── mutexlock.h
│ │ │ ├── options.cc
│ │ │ ├── posix_logger.h
│ │ │ ├── random.h
│ │ │ ├── status.cc
│ │ │ ├── testharness.cc
│ │ │ ├── testharness.h
│ │ │ ├── testutil.cc
│ │ │ └── testutil.h
│ ├── leveldb-hyper-conf
│ │ ├── linux
│ │ │ └── config.h
│ │ └── mac
│ │ │ └── config.h
│ ├── leveldb.gyp
│ └── port-libuv
│ │ ├── atomic_pointer_win.h
│ │ ├── env_win.cc
│ │ ├── port_uv.cc
│ │ ├── port_uv.h
│ │ ├── port_uv.h.bak
│ │ ├── stdint-msvc2008.h
│ │ ├── uv_condvar.h
│ │ ├── uv_condvar_posix.cc
│ │ ├── win_logger.cc
│ │ └── win_logger.h
└── snappy
│ ├── freebsd
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── linux
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── mac
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── snappy-1.1.1
│ ├── AUTHORS
│ ├── COPYING
│ ├── ChangeLog
│ ├── INSTALL
│ ├── Makefile.am
│ ├── Makefile.in
│ ├── NEWS
│ ├── README
│ ├── aclocal.m4
│ ├── autogen.sh
│ ├── config.guess
│ ├── config.h.in
│ ├── config.sub
│ ├── configure
│ ├── configure.ac
│ ├── depcomp
│ ├── format_description.txt
│ ├── framing_format.txt
│ ├── install-sh
│ ├── ltmain.sh
│ ├── m4
│ │ └── gtest.m4
│ ├── missing
│ ├── snappy-c.cc
│ ├── snappy-c.h
│ ├── snappy-internal.h
│ ├── snappy-sinksource.cc
│ ├── snappy-sinksource.h
│ ├── snappy-stubs-internal.cc
│ ├── snappy-stubs-internal.h
│ ├── snappy-stubs-public.h
│ ├── snappy-stubs-public.h.in
│ ├── snappy-test.cc
│ ├── snappy-test.h
│ ├── snappy.cc
│ ├── snappy.h
│ ├── snappy_unittest.cc
│ └── testdata
│ │ ├── alice29.txt
│ │ ├── asyoulik.txt
│ │ ├── baddata1.snappy
│ │ ├── baddata2.snappy
│ │ ├── baddata3.snappy
│ │ ├── cp.html
│ │ ├── fields.c
│ │ ├── geo.protodata
│ │ ├── grammar.lsp
│ │ ├── house.jpg
│ │ ├── html
│ │ ├── html_x_4
│ │ ├── kennedy.xls
│ │ ├── kppkn.gtb
│ │ ├── lcet10.txt
│ │ ├── mapreduce-osdi-1.pdf
│ │ ├── plrabn12.txt
│ │ ├── ptt5
│ │ ├── sum
│ │ ├── urls.10K
│ │ └── xargs.1
│ ├── snappy.gyp
│ ├── solaris
│ ├── config.h
│ └── snappy-stubs-public.h
│ └── win32
│ ├── config.h
│ └── snappy-stubs-public.h
├── iterator.js
├── leveldown-hyper.js
├── package.json
├── src
├── async.h
├── batch.cc
├── batch.h
├── batch_async.cc
├── batch_async.h
├── common.h
├── database.cc
├── database.h
├── database_async.cc
├── database_async.h
├── iterator.cc
├── iterator.h
├── iterator_async.cc
├── iterator_async.h
├── leveldown.cc
├── leveldown.h
├── leveldown_async.cc
└── leveldown_async.h
└── test
├── approximate-size-test.js
├── batch-test.js
├── chained-batch-test.js
├── cleanup-hanging-iterators-test.js
├── close-test.js
├── data
└── testdata.bin
├── del-test.js
├── destroy-test.js
├── get-test.js
├── getproperty-test.js
├── iterator-range-test.js
├── iterator-recursion-test.js
├── iterator-test.js
├── leak-tester-batch.js
├── leak-tester.js
├── leveldown-test.js
├── livebackup-test.js
├── make.js
├── open-test.js
├── port-libuv-fix-test.js
├── put-get-del-test.js
├── put-test.js
├── repair-test.js
└── stack-blower.js
/.dntrc:
--------------------------------------------------------------------------------
1 | ## DNT config file
2 | ## see https://github.com/rvagg/dnt
3 |
4 | NODE_VERSIONS="\
5 | v0.10.40 \
6 | v0.12.7 \
7 | "
8 | IOJS_VERSIONS="\
9 | v1.8.4 \
10 | v2.0.1 \
11 | v2.3.4 \
12 | v3.0.0-rc.3 \
13 | "
14 | OUTPUT_PREFIX="leveldown-"
15 | TEST_CMD="\
16 | cd /dnt/ && \
17 | npm install && \
18 | npm run-script prebuild \
19 | --nodedir=/usr/src/node/ && \
20 | node_modules/.bin/tape test/*-test.js \
21 | "
22 | # for tape
23 | LOG_OK_CMD="tail -2 | head -1 | sed 's/^# //'"
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | build/
3 | libleveldb.so
4 | libleveldb.a
5 | leakydb
6 | bench/
7 | *.sln
8 | *.vcxproj
9 | *.vcxproj.filters
10 | *.tlog
11 | *.obj
12 | *.1sdk.pdb
13 | *.lastbuildstate
14 | npm-debug.log
15 | prebuilds/
16 | .nyc_output/
17 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | *.tar.gz
2 | build/
3 | test-data.tar
4 | test-data.db.tar
5 | deps/leveldb/leveldb-basho/
6 | deps/leveldb/leveldb-hyper/
7 | deps/leveldb/leveldb-rocksdb/
8 | deps/snappy/snappy-1.1.1/testdata/
9 | leakydb
10 | bench/
11 | test/
12 | deps/leveldb/leveldb-1.17.0/doc/
13 | README
14 | INSTALL
15 | NEWS
16 | AUTHORS
17 | .nyc_output/
18 |
19 | .travis.yml
20 | .dntrc
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 |
3 | language: node_js
4 |
5 | before_install:
6 | - export JOBS=max
7 |
8 | os:
9 | - osx
10 | - linux
11 |
12 | node_js:
13 | - 6
14 | - 8
15 | - 10
16 |
17 | after_success: npm run coverage
18 |
19 | notifications:
20 | email: false
21 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | **Copyright © 2012-present [Contributors](CONTRIBUTORS.md).**
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # leveldown-hyper
2 |
3 | **Discontinued.**
4 |
5 | ---
6 |
7 | `leveldown-hyper` is a fork of `leveldown` and uses [`HyperLevelDB`](https://github.com/rescrv/HyperLevelDB) as backend. It extends the `leveldown` api with functionality to do live backups. This README only documents the `liveBackup()` method. For a complete reference we refer to [`leveldown`](https://github.com/Level/leveldown).
8 |
9 | `leveldown` can be considered an upstream repository to `leveldown-hyper` and any common logic and bug fixes will be merged from upstream into this repository.
10 |
11 | **If you are upgrading:** please see [UPGRADING.md](UPGRADING.md).
12 |
13 | ### `db.liveBackup(name, callback)`
14 |
15 | liveBackup()
is an instance method on an existing database object, used to make a live backup of the current state of the database.
16 |
17 | The `name` parameter is a `String`. A successful live backup will result in a backup folder named `backup-:name` inside the `location` folder of the current database.
18 |
19 | The `callback` function will be called with no arguments when a live backup was successful, or with a single `error` argument if the backup operation failed for any reason.
20 |
21 | ## Contributing
22 |
23 | [`Level/leveldown-hyper`](https://github.com/Level/leveldown-hyper) is an **OPEN Open Source Project**. This means that:
24 |
25 | > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
26 |
27 | See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.
28 |
29 | ## License
30 |
31 | [MIT](LICENSE.md) © 2012-present [Contributors](CONTRIBUTORS.md).
32 |
33 | _`leveldown-hyper` builds on the excellent work of the [`HyperLevelDB`](https://github.com/rescrv/HyperLevelDB) team and the LevelDB and Snappy teams from Google and additional contributors. HyperLevelDB, LevelDB and Snappy are issued under the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)._
34 |
--------------------------------------------------------------------------------
/UPGRADING.md:
--------------------------------------------------------------------------------
1 | # Upgrade Guide
2 |
3 | This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md).
4 |
5 | ## v2
6 |
7 | Dropped support for node 0.12, 4, 5, and 7.
8 |
9 | If you're using node v10 you'll need at least `leveldown-hyper@2.0.0` to successfully compile.
10 |
11 | ### `.batch(array)` enforces objects
12 |
13 | This major release contains an upgrade to `abstract-leveldown` with a [breaking change](https://github.com/Level/abstract-leveldown/commit/a2621ad70571f6ade9d2be42632ece042e068805) for the array version of `.batch()`. This change ensures all elements in the batch array are objects.
14 |
15 | If you previously passed arrays to `.batch()` that contained `undefined` or `null`, they would be silently ignored. Now this will produce an error.
16 |
--------------------------------------------------------------------------------
/bench/db-bench-plot.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | gnuplot <= concurrency || totalWrites > entryCount)
48 | return
49 |
50 | var time = process.hrtime()
51 | inProgress++
52 |
53 | db.put(uuid.v4(), data, function (err) {
54 | if (err)
55 | throw err
56 | writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
57 | inProgress--
58 | process.nextTick(write)
59 | })
60 |
61 | process.nextTick(write)
62 | }
63 |
64 | write()
65 | })
66 |
--------------------------------------------------------------------------------
/bench/write-sorted-plot.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | gnuplot <= concurrency || totalWrites > entryCount)
48 | return
49 |
50 | var time = process.hrtime()
51 | inProgress++
52 |
53 | db.put(timestamp(), data, function (err) {
54 | if (err)
55 | throw err
56 | writeBuf += (Date.now() - startTime) + ',' + process.hrtime(time)[1] + '\n'
57 | inProgress--
58 | process.nextTick(write)
59 | })
60 |
61 | process.nextTick(write)
62 | }
63 |
64 | write()
65 | })
66 |
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "targets": [{
3 | "target_name": "leveldownhyper"
4 | , "conditions": [
5 | ["OS == 'win'", {
6 | "defines": [
7 | "_HAS_EXCEPTIONS=0"
8 | ]
9 | , "msvs_settings": {
10 | "VCCLCompilerTool": {
11 | "RuntimeTypeInfo": "false"
12 | , "EnableFunctionLevelLinking": "true"
13 | , "ExceptionHandling": "2"
14 | , "DisableSpecificWarnings": [ "4355", "4530" ,"4267", "4244", "4506" ]
15 | }
16 | }
17 | }]
18 | , ['OS == "linux"', {
19 | 'cflags': [
20 | ]
21 | , 'cflags!': [ '-fno-tree-vrp' ]
22 | }]
23 | ]
24 | , "dependencies": [
25 | "<(module_root_dir)/deps/leveldb/leveldb.gyp:leveldb-hyper"
26 | ]
27 | , "include_dirs" : [
28 | "
3 |
4 | Google Inc.
5 |
6 | # Initial version authors:
7 | Jeffrey Dean
8 | Sanjay Ghemawat
9 |
10 | # Partial list of contributors:
11 | Kevin Regan
12 | Johan Bilien
13 |
14 | # HyperLevelDB authors:
15 | Robert Escriva
16 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/NEWS:
--------------------------------------------------------------------------------
1 | Release 1.2 2011-05-16
2 | ----------------------
3 |
4 | Fixes for larger databases (tested up to one billion 100-byte entries,
5 | i.e., ~100GB).
6 |
7 | (1) Place hard limit on number of level-0 files. This fixes errors
8 | of the form "too many open files".
9 |
10 | (2) Fixed memtable management. Before the fix, a heavy write burst
11 | could cause unbounded memory usage.
12 |
13 | A fix for a logging bug where the reader would incorrectly complain
14 | about corruption.
15 |
16 | Allow public access to WriteBatch contents so that users can easily
17 | wrap a DB.
18 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/README:
--------------------------------------------------------------------------------
1 | leveldb: A key-value store
2 | Authors: Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)
3 |
4 | The code under this directory implements a system for maintaining a
5 | persistent key/value store.
6 |
7 | See doc/index.html for more explanation.
8 | See doc/impl.html for a brief overview of the implementation.
9 |
10 | The public interface is in include/*.h. Callers should not include or
11 | rely on the details of any other header files in this package. Those
12 | internal APIs may be changed without warning.
13 |
14 | Guide to header files:
15 |
16 | include/db.h
17 | Main interface to the DB: Start here
18 |
19 | include/options.h
20 | Control over the behavior of an entire database, and also
21 | control over the behavior of individual reads and writes.
22 |
23 | include/comparator.h
24 | Abstraction for user-specified comparison function. If you want
25 | just bytewise comparison of keys, you can use the default comparator,
26 | but clients can write their own comparator implementations if they
27 | want custom ordering (e.g. to handle different character
28 | encodings, etc.)
29 |
30 | include/iterator.h
31 | Interface for iterating over data. You can get an iterator
32 | from a DB object.
33 |
34 | include/write_batch.h
35 | Interface for atomically applying multiple updates to a database.
36 |
37 | include/slice.h
38 | A simple module for maintaining a pointer and a length into some
39 | other byte array.
40 |
41 | include/status.h
42 | Status is returned from many of the public interfaces and is used
43 | to report success and various kinds of errors.
44 |
45 | include/env.h
46 | Abstraction of the OS environment. A posix implementation of
47 | this interface is in util/env_posix.cc
48 |
49 | include/table.h
50 | include/table_builder.h
51 | Lower-level modules that most clients probably won't use directly
52 |
53 | Install
54 | =======
55 |
56 | Get up and running quickly:
57 |
58 | $ autoreconf -i
59 | $ ./configure
60 | $ make
61 | # make install
62 | # ldconfig
63 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/TODO:
--------------------------------------------------------------------------------
1 | ss
2 | - Stats
3 |
4 | db
5 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key)
6 | that would blow away files whose ranges are entirely contained
7 | within [start_key..end_key]? For Chrome, deletion of obsolete
8 | object stores, etc. can be done in the background anyway, so
9 | probably not that important.
10 | - There have been requests for MultiGet.
11 |
12 | After a range is completely deleted, what gets rid of the
13 | corresponding files if we do no future changes to that range. Make
14 | the conditions for triggering compactions fire in more situations?
15 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/builder.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "db/builder.h"
6 |
7 | #include "db/filename.h"
8 | #include "db/dbformat.h"
9 | #include "db/table_cache.h"
10 | #include "db/version_edit.h"
11 | #include "hyperleveldb/db.h"
12 | #include "hyperleveldb/env.h"
13 | #include "hyperleveldb/iterator.h"
14 |
15 | namespace leveldb {
16 |
17 | Status BuildTable(const std::string& dbname,
18 | Env* env,
19 | const Options& options,
20 | TableCache* table_cache,
21 | Iterator* iter,
22 | FileMetaData* meta) {
23 | Status s;
24 | meta->file_size = 0;
25 | iter->SeekToFirst();
26 |
27 | std::string fname = SSTTableFileName(dbname, meta->number);
28 | if (iter->Valid()) {
29 | WritableFile* file;
30 | s = env->NewWritableFile(fname, &file);
31 | if (!s.ok()) {
32 | return s;
33 | }
34 |
35 | TableBuilder* builder = new TableBuilder(options, file);
36 | meta->smallest.DecodeFrom(iter->key());
37 | for (; iter->Valid(); iter->Next()) {
38 | Slice key = iter->key();
39 | meta->largest.DecodeFrom(key);
40 | builder->Add(key, iter->value());
41 | }
42 |
43 | // Finish and check for builder errors
44 | if (s.ok()) {
45 | s = builder->Finish();
46 | if (s.ok()) {
47 | meta->file_size = builder->FileSize();
48 | assert(meta->file_size > 0);
49 | }
50 | } else {
51 | builder->Abandon();
52 | }
53 | delete builder;
54 |
55 | // Finish and check for file errors
56 | if (s.ok()) {
57 | s = file->Sync();
58 | }
59 | if (s.ok()) {
60 | s = file->Close();
61 | }
62 | delete file;
63 | file = NULL;
64 |
65 | if (s.ok()) {
66 | // Verify that the table is usable
67 | Iterator* it = table_cache->NewIterator(ReadOptions(),
68 | meta->number,
69 | meta->file_size);
70 | s = it->status();
71 | delete it;
72 | }
73 | }
74 |
75 | // Check for input iterator errors
76 | if (!iter->status().ok()) {
77 | s = iter->status();
78 | }
79 |
80 | if (s.ok() && meta->file_size > 0) {
81 | // Keep it
82 | } else {
83 | env->DeleteFile(fname);
84 | }
85 | return s;
86 | }
87 |
88 | } // namespace leveldb
89 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/builder.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_
6 | #define STORAGE_LEVELDB_DB_BUILDER_H_
7 |
8 | #include "hyperleveldb/status.h"
9 |
10 | namespace leveldb {
11 |
12 | struct Options;
13 | struct FileMetaData;
14 |
15 | class Env;
16 | class Iterator;
17 | class TableCache;
18 | class VersionEdit;
19 |
20 | // Build a Table file from the contents of *iter. The generated file
21 | // will be named according to meta->number. On success, the rest of
22 | // *meta will be filled with metadata about the generated table.
23 | // If no data is present in *iter, meta->file_size will be set to
24 | // zero, and no Table file will be produced.
25 | extern Status BuildTable(const std::string& dbname,
26 | Env* env,
27 | const Options& options,
28 | TableCache* table_cache,
29 | Iterator* iter,
30 | FileMetaData* meta);
31 |
32 | } // namespace leveldb
33 |
34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_
35 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/db_iter.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_
6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_
7 |
8 | #include
9 | #include "hyperleveldb/db.h"
10 | #include "db/dbformat.h"
11 |
12 | namespace leveldb {
13 |
14 | class DBImpl;
15 |
16 | // Return a new iterator that converts internal keys (yielded by
17 | // "*internal_iter") that were live at the specified "sequence" number
18 | // into appropriate user keys.
19 | extern Iterator* NewDBIterator(
20 | DBImpl* db,
21 | const Comparator* user_key_comparator,
22 | Iterator* internal_iter,
23 | SequenceNumber sequence,
24 | uint32_t seed);
25 |
26 | } // namespace leveldb
27 |
28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_
29 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/filename.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // File names used by DB code
6 |
7 | #ifndef STORAGE_LEVELDB_DB_FILENAME_H_
8 | #define STORAGE_LEVELDB_DB_FILENAME_H_
9 |
10 | #include
11 | #include
12 | #include "hyperleveldb/slice.h"
13 | #include "hyperleveldb/status.h"
14 | #include "port/port.h"
15 |
16 | namespace leveldb {
17 |
18 | class Env;
19 |
20 | enum FileType {
21 | kLogFile,
22 | kDBLockFile,
23 | kTableFile,
24 | kDescriptorFile,
25 | kCurrentFile,
26 | kTempFile,
27 | kInfoLogFile // Either the current one, or an old one
28 | };
29 |
30 | // Return the name of the log file with the specified number
31 | // in the db named by "dbname". The result will be prefixed with
32 | // "dbname".
33 | extern std::string LogFileName(const std::string& dbname, uint64_t number);
34 |
35 | // Return the name of the sstable with the specified number
36 | // in the db named by "dbname". The result will be prefixed with
37 | // "dbname".
38 | extern std::string TableFileName(const std::string& dbname, uint64_t number);
39 |
40 | // Return the legacy file name for an sstable with the specified number
41 | // in the db named by "dbname". The result will be prefixed with
42 | // "dbname".
43 | extern std::string SSTTableFileName(const std::string& dbname, uint64_t number);
44 |
45 | // Return the name of the descriptor file for the db named by
46 | // "dbname" and the specified incarnation number. The result will be
47 | // prefixed with "dbname".
48 | extern std::string DescriptorFileName(const std::string& dbname,
49 | uint64_t number);
50 |
51 | // Return the name of the current file. This file contains the name
52 | // of the current manifest file. The result will be prefixed with
53 | // "dbname".
54 | extern std::string CurrentFileName(const std::string& dbname);
55 |
56 | // Return the name of the lock file for the db named by
57 | // "dbname". The result will be prefixed with "dbname".
58 | extern std::string LockFileName(const std::string& dbname);
59 |
60 | // Return the name of a temporary file owned by the db named "dbname".
61 | // The result will be prefixed with "dbname".
62 | extern std::string TempFileName(const std::string& dbname, uint64_t number);
63 |
64 | // Return the name of the info log file for "dbname".
65 | extern std::string InfoLogFileName(const std::string& dbname);
66 |
67 | // Return the name of the old info log file for "dbname".
68 | extern std::string OldInfoLogFileName(const std::string& dbname);
69 |
70 | // If filename is a leveldb file, store the type of the file in *type.
71 | // The number encoded in the filename is stored in *number. If the
72 | // filename was successfully parsed, returns true. Else return false.
73 | extern bool ParseFileName(const std::string& filename,
74 | uint64_t* number,
75 | FileType* type);
76 |
77 | // Make the CURRENT file point to the descriptor file with the
78 | // specified number.
79 | extern Status SetCurrentFile(Env* env, const std::string& dbname,
80 | uint64_t descriptor_number);
81 |
82 |
83 | } // namespace leveldb
84 |
85 | #endif // STORAGE_LEVELDB_DB_FILENAME_H_
86 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/log_format.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // Log format information shared by reader and writer.
6 | // See ../doc/log_format.txt for more detail.
7 |
8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_
9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_
10 |
11 | namespace leveldb {
12 | namespace log {
13 |
14 | enum RecordType {
15 | // Zero is reserved for preallocated files
16 | kZeroType = 0,
17 |
18 | kFullType = 1,
19 |
20 | // For fragments
21 | kFirstType = 2,
22 | kMiddleType = 3,
23 | kLastType = 4
24 | };
25 | static const int kMaxRecordType = kLastType;
26 |
27 | static const int kBlockSize = 32768;
28 |
29 | // Header is checksum (4 bytes), type (1 byte), length (2 bytes).
30 | static const int kHeaderSize = 4 + 1 + 2;
31 |
32 | } // namespace log
33 | } // namespace leveldb
34 |
35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_
36 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/log_writer.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_
7 |
8 | #include
9 | #include "db/log_format.h"
10 | #include "hyperleveldb/slice.h"
11 | #include "hyperleveldb/status.h"
12 | #include "port/port.h"
13 |
14 | namespace leveldb {
15 |
16 | class WritableFile;
17 |
18 | namespace log {
19 |
20 | class Writer {
21 | public:
22 | // Create a writer that will append data to "*dest".
23 | // "*dest" must be initially empty.
24 | // "*dest" must remain live while this Writer is in use.
25 | explicit Writer(WritableFile* dest);
26 | ~Writer();
27 |
28 | Status AddRecord(const Slice& slice);
29 |
30 | private:
31 | WritableFile* dest_;
32 | port::Mutex offset_mtx_;
33 | uint64_t offset_; // Current offset in file
34 |
35 | // crc32c values for all supported record types. These are
36 | // pre-computed to reduce the overhead of computing the crc of the
37 | // record type stored in the header.
38 | uint32_t type_crc_[kMaxRecordType + 1];
39 |
40 | Status EmitPhysicalRecordAt(RecordType type, const char* ptr, uint64_t offset, size_t length);
41 |
42 | // No copying allowed
43 | Writer(const Writer&);
44 | void operator=(const Writer&);
45 | };
46 |
47 | } // namespace log
48 | } // namespace leveldb
49 |
50 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_
51 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/memtable.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_
6 | #define STORAGE_LEVELDB_DB_MEMTABLE_H_
7 |
8 | #include
9 | #include "hyperleveldb/db.h"
10 | #include "db/dbformat.h"
11 | #include "db/skiplist.h"
12 | #include "util/arena.h"
13 |
14 | namespace leveldb {
15 |
16 | class InternalKeyComparator;
17 | class Mutex;
18 | class MemTableIterator;
19 |
20 | class MemTable {
21 | public:
22 | // MemTables are reference counted. The initial reference count
23 | // is zero and the caller must call Ref() at least once.
24 | explicit MemTable(const InternalKeyComparator& comparator);
25 |
26 | // Increase reference count.
27 | // XXX use a release increment if not using GCC intrinsics
28 | void Ref() { __sync_add_and_fetch(&refs_, 1); }
29 |
30 | // Drop reference count. Delete if no more references exist.
31 | // XXX use an acquire decrement if not using GCC intrinsics
32 | void Unref() {
33 | int refs = __sync_sub_and_fetch(&refs_, 1);
34 | assert(refs >= 0);
35 | if (refs <= 0) {
36 | delete this;
37 | }
38 | }
39 |
40 | // Returns an estimate of the number of bytes of data in use by this
41 | // data structure.
42 | //
43 | // REQUIRES: external synchronization to prevent simultaneous
44 | // operations on the same MemTable.
45 | size_t ApproximateMemoryUsage();
46 |
47 | // Return an iterator that yields the contents of the memtable.
48 | //
49 | // The caller must ensure that the underlying MemTable remains live
50 | // while the returned iterator is live. The keys returned by this
51 | // iterator are internal keys encoded by AppendInternalKey in the
52 | // db/format.{h,cc} module.
53 | Iterator* NewIterator();
54 |
55 | // Add an entry into memtable that maps key to value at the
56 | // specified sequence number and with the specified type.
57 | // Typically value will be empty if type==kTypeDeletion.
58 | void Add(SequenceNumber seq, ValueType type,
59 | const Slice& key,
60 | const Slice& value);
61 |
62 | // If memtable contains a value for key, store it in *value and return true.
63 | // If memtable contains a deletion for key, store a NotFound() error
64 | // in *status and return true.
65 | // Else, return false.
66 | bool Get(const LookupKey& key, std::string* value, Status* s);
67 |
68 | private:
69 | ~MemTable(); // Private since only Unref() should be used to delete it
70 | typedef std::pair TableKey;
71 |
72 | struct KeyComparator {
73 | const InternalKeyComparator comparator;
74 | explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { }
75 | int operator()(TableKey a, TableKey b) const;
76 | };
77 | friend class MemTableIterator;
78 | friend class MemTableBackwardIterator;
79 |
80 | typedef SkipList Table;
81 |
82 | KeyComparator comparator_;
83 | int refs_;
84 | port::Mutex mtx_;
85 | Arena arena_;
86 | Table table_;
87 |
88 | // No copying allowed
89 | MemTable(const MemTable&);
90 | void operator=(const MemTable&);
91 | };
92 |
93 | } // namespace leveldb
94 |
95 | #endif // STORAGE_LEVELDB_DB_MEMTABLE_H_
96 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/replay_iterator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013 The HyperLevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_ROLLING_ITERATOR_H_
6 | #define STORAGE_LEVELDB_DB_ROLLING_ITERATOR_H_
7 |
8 | #include
9 | #include
10 | #include "hyperleveldb/db.h"
11 | #include "hyperleveldb/replay_iterator.h"
12 | #include "db/dbformat.h"
13 | #include "db/memtable.h"
14 |
15 | namespace leveldb {
16 |
17 | class DBImpl;
18 | struct ReplayState {
19 | ReplayState(Iterator* i, SequenceNumber s, SequenceNumber l);
20 | ReplayState(MemTable* m, SequenceNumber s);
21 | MemTable* mem_;
22 | Iterator* iter_;
23 | SequenceNumber seq_start_;
24 | SequenceNumber seq_limit_;
25 | };
26 |
27 | class ReplayIteratorImpl : public ReplayIterator {
28 | public:
29 | // Refs the memtable on its own; caller must hold mutex while creating this
30 | ReplayIteratorImpl(DBImpl* db, port::Mutex* mutex, const Comparator* cmp,
31 | Iterator* iter, MemTable* m, SequenceNumber s);
32 | virtual bool Valid();
33 | virtual void Next();
34 | virtual bool HasValue();
35 | virtual Slice key() const;
36 | virtual Slice value() const;
37 | virtual Status status() const;
38 |
39 | // extra interface
40 |
41 | // we ref the memtable; caller holds mutex passed into ctor
42 | // REQUIRES: caller must hold mutex passed into ctor
43 | void enqueue(MemTable* m, SequenceNumber s);
44 |
45 | // REQUIRES: caller must hold mutex passed into ctor
46 | void cleanup(); // calls delete this;
47 |
48 | private:
49 | virtual ~ReplayIteratorImpl();
50 | bool ParseKey(ParsedInternalKey* ikey);
51 | bool ParseKey(const Slice& k, ParsedInternalKey* ikey);
52 | void Prime();
53 |
54 | DBImpl* const db_;
55 | port::Mutex* mutex_;
56 | const Comparator* const user_comparator_;
57 | SequenceNumber const start_at_;
58 | bool valid_;
59 | Status status_;
60 |
61 | bool has_current_user_key_;
62 | std::string current_user_key_;
63 | SequenceNumber current_user_sequence_;
64 |
65 | ReplayState rs_;
66 | std::list mems_;
67 | };
68 |
69 | } // namespace leveldb
70 |
71 | #endif // STORAGE_LEVELDB_DB_ROLLING_ITERATOR_H_
72 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/snapshot.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
7 |
8 | #include "hyperleveldb/db.h"
9 |
10 | namespace leveldb {
11 |
12 | class SnapshotList;
13 |
14 | // Snapshots are kept in a doubly-linked list in the DB.
15 | // Each SnapshotImpl corresponds to a particular sequence number.
16 | class SnapshotImpl : public Snapshot {
17 | public:
18 | SequenceNumber number_; // const after creation
19 |
20 | private:
21 | friend class SnapshotList;
22 |
23 | // SnapshotImpl is kept in a doubly-linked circular list
24 | SnapshotImpl* prev_;
25 | SnapshotImpl* next_;
26 |
27 | SnapshotList* list_; // just for sanity checks
28 | };
29 |
30 | class SnapshotList {
31 | public:
32 | SnapshotList() {
33 | list_.prev_ = &list_;
34 | list_.next_ = &list_;
35 | }
36 |
37 | bool empty() const { return list_.next_ == &list_; }
38 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
39 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
40 |
41 | const SnapshotImpl* New(SequenceNumber seq) {
42 | SnapshotImpl* s = new SnapshotImpl;
43 | s->number_ = seq;
44 | s->list_ = this;
45 | s->next_ = &list_;
46 | s->prev_ = list_.prev_;
47 | s->prev_->next_ = s;
48 | s->next_->prev_ = s;
49 | return s;
50 | }
51 |
52 | void Delete(const SnapshotImpl* s) {
53 | assert(s->list_ == this);
54 | s->prev_->next_ = s->next_;
55 | s->next_->prev_ = s->prev_;
56 | delete s;
57 | }
58 |
59 | private:
60 | // Dummy head of doubly-linked list of snapshots
61 | SnapshotImpl list_;
62 | };
63 |
64 | } // namespace leveldb
65 |
66 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
67 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/table_cache.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // Thread-safe (provides internal synchronization)
6 |
7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_
8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_
9 |
10 | #include
11 | #include
12 | #include "db/dbformat.h"
13 | #include "hyperleveldb/cache.h"
14 | #include "hyperleveldb/table.h"
15 | #include "port/port.h"
16 |
17 | namespace leveldb {
18 |
19 | class Env;
20 |
21 | class TableCache {
22 | public:
23 | TableCache(const std::string& dbname, const Options* options, int entries);
24 | ~TableCache();
25 |
26 | // Return an iterator for the specified file number (the corresponding
27 | // file length must be exactly "file_size" bytes). If "tableptr" is
28 | // non-NULL, also sets "*tableptr" to point to the Table object
29 | // underlying the returned iterator, or NULL if no Table object underlies
30 | // the returned iterator. The returned "*tableptr" object is owned by
31 | // the cache and should not be deleted, and is valid for as long as the
32 | // returned iterator is live.
33 | Iterator* NewIterator(const ReadOptions& options,
34 | uint64_t file_number,
35 | uint64_t file_size,
36 | Table** tableptr = NULL);
37 |
38 | // If a seek to internal key "k" in specified file finds an entry,
39 | // call (*handle_result)(arg, found_key, found_value).
40 | Status Get(const ReadOptions& options,
41 | uint64_t file_number,
42 | uint64_t file_size,
43 | const Slice& k,
44 | void* arg,
45 | void (*handle_result)(void*, const Slice&, const Slice&));
46 |
47 | // Evict any entry for the specified file number
48 | void Evict(uint64_t file_number);
49 |
50 | private:
51 | Env* const env_;
52 | const std::string dbname_;
53 | const Options* options_;
54 | Cache* cache_;
55 |
56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**);
57 | };
58 |
59 | } // namespace leveldb
60 |
61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_
62 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/version_edit_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "db/version_edit.h"
6 | #include "util/testharness.h"
7 |
8 | namespace leveldb {
9 |
10 | static void TestEncodeDecode(const VersionEdit& edit) {
11 | std::string encoded, encoded2;
12 | edit.EncodeTo(&encoded);
13 | VersionEdit parsed;
14 | Status s = parsed.DecodeFrom(encoded);
15 | ASSERT_TRUE(s.ok()) << s.ToString();
16 | parsed.EncodeTo(&encoded2);
17 | ASSERT_EQ(encoded, encoded2);
18 | }
19 |
20 | class VersionEditTest { };
21 |
22 | TEST(VersionEditTest, EncodeDecode) {
23 | static const uint64_t kBig = 1ull << 50;
24 |
25 | VersionEdit edit;
26 | for (int i = 0; i < 4; i++) {
27 | TestEncodeDecode(edit);
28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i,
29 | InternalKey("foo", kBig + 500 + i, kTypeValue),
30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion));
31 | edit.DeleteFile(4, kBig + 700 + i);
32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue));
33 | }
34 |
35 | edit.SetComparatorName("foo");
36 | edit.SetLogNumber(kBig + 100);
37 | edit.SetNextFile(kBig + 200);
38 | edit.SetLastSequence(kBig + 1000);
39 | TestEncodeDecode(edit);
40 | }
41 |
42 | } // namespace leveldb
43 |
44 | int main(int argc, char** argv) {
45 | return leveldb::test::RunAllTests();
46 | }
47 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/db/write_batch_internal.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
7 |
8 | #include "hyperleveldb/write_batch.h"
9 |
10 | namespace leveldb {
11 |
12 | class MemTable;
13 |
14 | // WriteBatchInternal provides static methods for manipulating a
15 | // WriteBatch that we don't want in the public WriteBatch interface.
16 | class WriteBatchInternal {
17 | public:
18 | // Return the number of entries in the batch.
19 | static int Count(const WriteBatch* batch);
20 |
21 | // Set the count for the number of entries in the batch.
22 | static void SetCount(WriteBatch* batch, int n);
23 |
24 | // Return the seqeunce number for the start of this batch.
25 | static SequenceNumber Sequence(const WriteBatch* batch);
26 |
27 | // Store the specified number as the seqeunce number for the start of
28 | // this batch.
29 | static void SetSequence(WriteBatch* batch, SequenceNumber seq);
30 |
31 | static Slice Contents(const WriteBatch* batch) {
32 | return Slice(batch->rep_);
33 | }
34 |
35 | static size_t ByteSize(const WriteBatch* batch) {
36 | return batch->rep_.size();
37 | }
38 |
39 | static void SetContents(WriteBatch* batch, const Slice& contents);
40 |
41 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable);
42 |
43 | static void Append(WriteBatch* dst, const WriteBatch* src);
44 | };
45 |
46 | } // namespace leveldb
47 |
48 |
49 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
50 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/doc/doc.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin-left: 0.5in;
3 | margin-right: 0.5in;
4 | background: white;
5 | color: black;
6 | }
7 |
8 | h1 {
9 | margin-left: -0.2in;
10 | font-size: 14pt;
11 | }
12 | h2 {
13 | margin-left: -0in;
14 | font-size: 12pt;
15 | }
16 | h3 {
17 | margin-left: -0in;
18 | }
19 | h4 {
20 | margin-left: -0in;
21 | }
22 | hr {
23 | margin-left: -0in;
24 | }
25 |
26 | /* Definition lists: definition term bold */
27 | dt {
28 | font-weight: bold;
29 | }
30 |
31 | address {
32 | text-align: center;
33 | }
34 | code,samp,var {
35 | color: blue;
36 | }
37 | kbd {
38 | color: #600000;
39 | }
40 | div.note p {
41 | float: right;
42 | width: 3in;
43 | margin-right: 0%;
44 | padding: 1px;
45 | border: 2px solid #6060a0;
46 | background-color: #fffff0;
47 | }
48 |
49 | ul {
50 | margin-top: -0em;
51 | margin-bottom: -0em;
52 | }
53 |
54 | ol {
55 | margin-top: -0em;
56 | margin-bottom: -0em;
57 | }
58 |
59 | UL.nobullets {
60 | list-style-type: none;
61 | list-style-image: none;
62 | margin-left: -1em;
63 | }
64 |
65 | p {
66 | margin: 1em 0 1em 0;
67 | padding: 0 0 0 0;
68 | }
69 |
70 | pre {
71 | line-height: 1.3em;
72 | padding: 0.4em 0 0.8em 0;
73 | margin: 0 0 0 0;
74 | border: 0 0 0 0;
75 | color: blue;
76 | }
77 |
78 | .datatable {
79 | margin-left: auto;
80 | margin-right: auto;
81 | margin-top: 2em;
82 | margin-bottom: 2em;
83 | border: 1px solid;
84 | }
85 |
86 | .datatable td,th {
87 | padding: 0 0.5em 0 0.5em;
88 | text-align: right;
89 | }
90 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/doc/log_format.txt:
--------------------------------------------------------------------------------
1 | The log file contents are a sequence of 32KB blocks. The only
2 | exception is that the tail of the file may contain a partial block.
3 |
4 | Each block consists of a sequence of records:
5 | block := record* trailer?
6 | record :=
7 | checksum: uint32 // crc32c of type and data[] ; little-endian
8 | length: uint16 // little-endian
9 | type: uint8 // One of FULL, FIRST, MIDDLE, LAST
10 | data: uint8[length]
11 |
12 | A record never starts within the last six bytes of a block (since it
13 | won't fit). Any leftover bytes here form the trailer, which must
14 | consist entirely of zero bytes and must be skipped by readers.
15 |
16 | Aside: if exactly seven bytes are left in the current block, and a new
17 | non-zero length record is added, the writer must emit a FIRST record
18 | (which contains zero bytes of user data) to fill up the trailing seven
19 | bytes of the block and then emit all of the user data in subsequent
20 | blocks.
21 |
22 | More types may be added in the future. Some Readers may skip record
23 | types they do not understand, others may report that some data was
24 | skipped.
25 |
26 | FULL == 1
27 | FIRST == 2
28 | MIDDLE == 3
29 | LAST == 4
30 |
31 | The FULL record contains the contents of an entire user record.
32 |
33 | FIRST, MIDDLE, LAST are types used for user records that have been
34 | split into multiple fragments (typically because of block boundaries).
35 | FIRST is the type of the first fragment of a user record, LAST is the
36 | type of the last fragment of a user record, and MID is the type of all
37 | interior fragments of a user record.
38 |
39 | Example: consider a sequence of user records:
40 | A: length 1000
41 | B: length 97270
42 | C: length 8000
43 | A will be stored as a FULL record in the first block.
44 |
45 | B will be split into three fragments: first fragment occupies the rest
46 | of the first block, second fragment occupies the entirety of the
47 | second block, and the third fragment occupies a prefix of the third
48 | block. This will leave six bytes free in the third block, which will
49 | be left empty as the trailer.
50 |
51 | C will be stored as a FULL record in the fourth block.
52 |
53 | ===================
54 |
55 | Some benefits over the recordio format:
56 |
57 | (1) We do not need any heuristics for resyncing - just go to next
58 | block boundary and scan. If there is a corruption, skip to the next
59 | block. As a side-benefit, we do not get confused when part of the
60 | contents of one log file are embedded as a record inside another log
61 | file.
62 |
63 | (2) Splitting at approximate boundaries (e.g., for mapreduce) is
64 | simple: find the next block boundary and skip records until we
65 | hit a FULL or FIRST record.
66 |
67 | (3) We do not need extra buffering for large records.
68 |
69 | Some downsides compared to recordio format:
70 |
71 | (1) No packing of tiny records. This could be fixed by adding a new
72 | record type, so it is a shortcoming of the current implementation,
73 | not necessarily the format.
74 |
75 | (2) No compression. Again, this could be fixed by adding new record types.
76 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/helpers/memenv/memenv.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
7 |
8 | namespace leveldb {
9 |
10 | class Env;
11 |
12 | // Returns a new environment that stores its data in memory and delegates
13 | // all non-file-storage tasks to base_env. The caller must delete the result
14 | // when it is no longer needed.
15 | // *base_env must remain live while the result is in use.
16 | Env* NewMemEnv(Env* base_env);
17 |
18 | } // namespace leveldb
19 |
20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
21 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb.upack.in:
--------------------------------------------------------------------------------
1 | package hyperleveldb
2 | | source="hyperleveldb"
3 | | debian name="libhyperleveldb0"
4 | | version="@VERSION@"
5 | | release="1"
6 | | license="BSD"
7 | | copyright="2011-2013 The LevelDB Authors"
8 | | homepage="http://hyperdex.org"
9 | | tarball="http://hyperdex.org/src/hyperleveldb-{version}.tar.gz"
10 | | debian section="libs"
11 | | configure="--disable-static"
12 | | summary="A fast key-value storage library"
13 | + {libdir}/libhyperleveldb.so.0
14 | + {libdir}/libhyperleveldb.so.0.0.0
15 | '''LevelDB is a fast key-value storage library written at Google that provides
16 | an ordered mapping from string keys to string values.'''
17 |
18 | subpackage hyperleveldb-devel
19 | | debian name="libhyperleveldb-dev"
20 | | debian section="libdevel"
21 | | debian requires="libhyperleveldb0{self}"
22 | | fedora requires="hyperleveldb{self}"
23 | | summary="A fast key-value storage library (development files)"
24 | + {includedir}/hyperleveldb/cache.h
25 | + {includedir}/hyperleveldb/c.h
26 | + {includedir}/hyperleveldb/comparator.h
27 | + {includedir}/hyperleveldb/db.h
28 | + {includedir}/hyperleveldb/env.h
29 | + {includedir}/hyperleveldb/filter_policy.h
30 | + {includedir}/hyperleveldb/iterator.h
31 | + {includedir}/hyperleveldb/options.h
32 | + {includedir}/hyperleveldb/replay_iterator.h
33 | + {includedir}/hyperleveldb/slice.h
34 | + {includedir}/hyperleveldb/status.h
35 | + {includedir}/hyperleveldb/table_builder.h
36 | + {includedir}/hyperleveldb/table.h
37 | + {includedir}/hyperleveldb/write_batch.h
38 | + {libdir}/libhyperleveldb.so
39 | + {libdir}/pkgconfig/libhyperleveldb.pc
40 |
41 | exclude {libdir}/libhyperleveldb.la
42 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/comparator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
6 | #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
7 |
8 | #include
9 | #include
10 |
11 | namespace leveldb {
12 |
13 | class Slice;
14 |
15 | // A Comparator object provides a total order across slices that are
16 | // used as keys in an sstable or a database. A Comparator implementation
17 | // must be thread-safe since leveldb may invoke its methods concurrently
18 | // from multiple threads.
19 | class Comparator {
20 | public:
21 | virtual ~Comparator();
22 |
23 | // Three-way comparison. Returns value:
24 | // < 0 iff "a" < "b",
25 | // == 0 iff "a" == "b",
26 | // > 0 iff "a" > "b"
27 | virtual int Compare(const Slice& a, const Slice& b) const = 0;
28 |
29 | // The name of the comparator. Used to check for comparator
30 | // mismatches (i.e., a DB created with one comparator is
31 | // accessed using a different comparator.
32 | //
33 | // The client of this package should switch to a new name whenever
34 | // the comparator implementation changes in a way that will cause
35 | // the relative ordering of any two keys to change.
36 | //
37 | // Names starting with "leveldb." are reserved and should not be used
38 | // by any clients of this package.
39 | virtual const char* Name() const = 0;
40 |
41 | // Advanced functions: these are used to reduce the space requirements
42 | // for internal data structures like index blocks.
43 |
44 | // If *start < limit, changes *start to a short string in [start,limit).
45 | // Simple comparator implementations may return with *start unchanged,
46 | // i.e., an implementation of this method that does nothing is correct.
47 | virtual void FindShortestSeparator(
48 | std::string* start,
49 | const Slice& limit) const = 0;
50 |
51 | // Changes *key to a short string >= *key.
52 | // Simple comparator implementations may return with *key unchanged,
53 | // i.e., an implementation of this method that does nothing is correct.
54 | virtual void FindShortSuccessor(std::string* key) const = 0;
55 |
56 | // If unsure, return 0;
57 | virtual uint64_t KeyNum(const Slice& key) const;
58 | };
59 |
60 | // Return a builtin comparator that uses lexicographic byte-wise
61 | // ordering. The result remains the property of this module and
62 | // must not be deleted.
63 | extern const Comparator* BytewiseComparator();
64 |
65 | } // namespace leveldb
66 |
67 | #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
68 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/filter_policy.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // A database can be configured with a custom FilterPolicy object.
6 | // This object is responsible for creating a small filter from a set
7 | // of keys. These filters are stored in leveldb and are consulted
8 | // automatically by leveldb to decide whether or not to read some
9 | // information from disk. In many cases, a filter can cut down the
10 | // number of disk seeks form a handful to a single disk seek per
11 | // DB::Get() call.
12 | //
13 | // Most people will want to use the builtin bloom filter support (see
14 | // NewBloomFilterPolicy() below).
15 |
16 | #ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
17 | #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
18 |
19 | #include
20 |
21 | namespace leveldb {
22 |
23 | class Slice;
24 |
25 | class FilterPolicy {
26 | public:
27 | virtual ~FilterPolicy();
28 |
29 | // Return the name of this policy. Note that if the filter encoding
30 | // changes in an incompatible way, the name returned by this method
31 | // must be changed. Otherwise, old incompatible filters may be
32 | // passed to methods of this type.
33 | virtual const char* Name() const = 0;
34 |
35 | // keys[0,n-1] contains a list of keys (potentially with duplicates)
36 | // that are ordered according to the user supplied comparator.
37 | // Append a filter that summarizes keys[0,n-1] to *dst.
38 | //
39 | // Warning: do not change the initial contents of *dst. Instead,
40 | // append the newly constructed filter to *dst.
41 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst)
42 | const = 0;
43 |
44 | // "filter" contains the data appended by a preceding call to
45 | // CreateFilter() on this class. This method must return true if
46 | // the key was in the list of keys passed to CreateFilter().
47 | // This method may return true or false if the key was not on the
48 | // list, but it should aim to return false with a high probability.
49 | virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const = 0;
50 | };
51 |
52 | // Return a new filter policy that uses a bloom filter with approximately
53 | // the specified number of bits per key. A good value for bits_per_key
54 | // is 10, which yields a filter with ~ 1% false positive rate.
55 | //
56 | // Callers must delete the result after any database that is using the
57 | // result has been closed.
58 | //
59 | // Note: if you are using a custom comparator that ignores some parts
60 | // of the keys being compared, you must not use NewBloomFilterPolicy()
61 | // and must provide your own FilterPolicy that also ignores the
62 | // corresponding parts of the keys. For example, if the comparator
63 | // ignores trailing spaces, it would be incorrect to use a
64 | // FilterPolicy (like NewBloomFilterPolicy) that does not ignore
65 | // trailing spaces in keys.
66 | extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
67 |
68 | }
69 |
70 | #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
71 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/replay_iterator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013 The HyperLevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_
6 | #define STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_
7 |
8 | #include "hyperleveldb/slice.h"
9 | #include "hyperleveldb/status.h"
10 |
11 | namespace leveldb {
12 |
13 | class ReplayIterator {
14 | public:
15 | ReplayIterator();
16 |
17 | // An iterator is either positioned at a deleted key, present key/value pair,
18 | // or not valid. This method returns true iff the iterator is valid.
19 | virtual bool Valid() = 0;
20 |
21 | // Moves to the next entry in the source. After this call, Valid() is
22 | // true iff the iterator was not positioned at the last entry in the source.
23 | // REQUIRES: Valid()
24 | virtual void Next() = 0;
25 |
26 | // Return true if the current entry points to a key-value pair. If this
27 | // returns false, it means the current entry is a deleted entry.
28 | virtual bool HasValue() = 0;
29 |
30 | // Return the key for the current entry. The underlying storage for
31 | // the returned slice is valid only until the next modification of
32 | // the iterator.
33 | // REQUIRES: Valid()
34 | virtual Slice key() const = 0;
35 |
36 | // Return the value for the current entry. The underlying storage for
37 | // the returned slice is valid only until the next modification of
38 | // the iterator.
39 | // REQUIRES: !AtEnd() && !AtStart()
40 | virtual Slice value() const = 0;
41 |
42 | // If an error has occurred, return it. Else return an ok status.
43 | virtual Status status() const = 0;
44 |
45 | protected:
46 | // must be released by giving it back to the DB
47 | virtual ~ReplayIterator();
48 |
49 | private:
50 | // No copying allowed
51 | ReplayIterator(const ReplayIterator&);
52 | void operator=(const ReplayIterator&);
53 | };
54 |
55 | } // namespace leveldb
56 |
57 | #endif // STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_
58 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/table.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_
6 | #define STORAGE_LEVELDB_INCLUDE_TABLE_H_
7 |
8 | #include
9 | #include "hyperleveldb/iterator.h"
10 |
11 | namespace leveldb {
12 |
13 | class Block;
14 | class BlockHandle;
15 | class Footer;
16 | struct Options;
17 | class RandomAccessFile;
18 | struct ReadOptions;
19 | class TableCache;
20 |
21 | // A Table is a sorted map from strings to strings. Tables are
22 | // immutable and persistent. A Table may be safely accessed from
23 | // multiple threads without external synchronization.
24 | class Table {
25 | public:
26 | // Attempt to open the table that is stored in bytes [0..file_size)
27 | // of "file", and read the metadata entries necessary to allow
28 | // retrieving data from the table.
29 | //
30 | // If successful, returns ok and sets "*table" to the newly opened
31 | // table. The client should delete "*table" when no longer needed.
32 | // If there was an error while initializing the table, sets "*table"
33 | // to NULL and returns a non-ok status. Does not take ownership of
34 | // "*source", but the client must ensure that "source" remains live
35 | // for the duration of the returned table's lifetime.
36 | //
37 | // *file must remain live while this Table is in use.
38 | static Status Open(const Options& options,
39 | RandomAccessFile* file,
40 | uint64_t file_size,
41 | Table** table);
42 |
43 | ~Table();
44 |
45 | // Returns a new iterator over the table contents.
46 | // The result of NewIterator() is initially invalid (caller must
47 | // call one of the Seek methods on the iterator before using it).
48 | Iterator* NewIterator(const ReadOptions&) const;
49 |
50 | // Given a key, return an approximate byte offset in the file where
51 | // the data for that key begins (or would begin if the key were
52 | // present in the file). The returned value is in terms of file
53 | // bytes, and so includes effects like compression of the underlying data.
54 | // E.g., the approximate offset of the last key in the table will
55 | // be close to the file length.
56 | uint64_t ApproximateOffsetOf(const Slice& key) const;
57 |
58 | private:
59 | struct Rep;
60 | Rep* rep_;
61 |
62 | explicit Table(Rep* rep) { rep_ = rep; }
63 | static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
64 |
65 | // Calls (*handle_result)(arg, ...) with the entry found after a call
66 | // to Seek(key). May not make such a call if filter policy says
67 | // that key is not present.
68 | friend class TableCache;
69 | Status InternalGet(
70 | const ReadOptions&, const Slice& key,
71 | void* arg,
72 | void (*handle_result)(void* arg, const Slice& k, const Slice& v));
73 |
74 |
75 | void ReadMeta(const Footer& footer);
76 | void ReadFilter(const Slice& filter_handle_value);
77 |
78 | // No copying allowed
79 | Table(const Table&);
80 | void operator=(const Table&);
81 | };
82 |
83 | } // namespace leveldb
84 |
85 | #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_
86 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/hyperleveldb/write_batch.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // WriteBatch holds a collection of updates to apply atomically to a DB.
6 | //
7 | // The updates are applied in the order in which they are added
8 | // to the WriteBatch. For example, the value of "key" will be "v3"
9 | // after the following batch is written:
10 | //
11 | // batch.Put("key", "v1");
12 | // batch.Delete("key");
13 | // batch.Put("key", "v2");
14 | // batch.Put("key", "v3");
15 | //
16 | // Multiple threads can invoke const methods on a WriteBatch without
17 | // external synchronization, but if any of the threads may call a
18 | // non-const method, all threads accessing the same WriteBatch must use
19 | // external synchronization.
20 |
21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
23 |
24 | #include
25 | #include "hyperleveldb/status.h"
26 |
27 | namespace leveldb {
28 |
29 | class Slice;
30 |
31 | class WriteBatch {
32 | public:
33 | WriteBatch();
34 | ~WriteBatch();
35 |
36 | // Store the mapping "key->value" in the database.
37 | void Put(const Slice& key, const Slice& value);
38 |
39 | // If the database contains a mapping for "key", erase it. Else do nothing.
40 | void Delete(const Slice& key);
41 |
42 | // Clear all updates buffered in this batch.
43 | void Clear();
44 |
45 | // Support for iterating over the contents of a batch.
46 | class Handler {
47 | public:
48 | virtual ~Handler();
49 | virtual void Put(const Slice& key, const Slice& value) = 0;
50 | virtual void Delete(const Slice& key) = 0;
51 | };
52 | Status Iterate(Handler* handler) const;
53 |
54 | private:
55 | friend class WriteBatchInternal;
56 |
57 | std::string rep_; // See comment in write_batch.cc for the format of rep_
58 |
59 | // Intentionally copyable
60 | };
61 |
62 | } // namespace leveldb
63 |
64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
65 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/issues/issue178_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | // Test for issue 178: a manual compaction causes deleted data to reappear.
6 | #include
7 | #include
8 | #include
9 |
10 | #include "hyperleveldb/db.h"
11 | #include "hyperleveldb/write_batch.h"
12 | #include "util/testharness.h"
13 |
14 | namespace {
15 |
16 | const int kNumKeys = 1100000;
17 |
18 | std::string Key1(int i) {
19 | char buf[100];
20 | snprintf(buf, sizeof(buf), "my_key_%d", i);
21 | return buf;
22 | }
23 |
24 | std::string Key2(int i) {
25 | return Key1(i) + "_xxx";
26 | }
27 |
28 | class Issue178 { };
29 |
30 | TEST(Issue178, Test) {
31 | // Get rid of any state from an old run.
32 | std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test";
33 | DestroyDB(dbpath, leveldb::Options());
34 |
35 | // Open database. Disable compression since it affects the creation
36 | // of layers and the code below is trying to test against a very
37 | // specific scenario.
38 | leveldb::DB* db;
39 | leveldb::Options db_options;
40 | db_options.create_if_missing = true;
41 | db_options.compression = leveldb::kNoCompression;
42 | ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db));
43 |
44 | // create first key range
45 | leveldb::WriteBatch batch;
46 | for (size_t i = 0; i < kNumKeys; i++) {
47 | batch.Put(Key1(i), "value for range 1 key");
48 | }
49 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
50 |
51 | // create second key range
52 | batch.Clear();
53 | for (size_t i = 0; i < kNumKeys; i++) {
54 | batch.Put(Key2(i), "value for range 2 key");
55 | }
56 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
57 |
58 | // delete second key range
59 | batch.Clear();
60 | for (size_t i = 0; i < kNumKeys; i++) {
61 | batch.Delete(Key2(i));
62 | }
63 | ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch));
64 |
65 | // compact database
66 | std::string start_key = Key1(0);
67 | std::string end_key = Key1(kNumKeys - 1);
68 | leveldb::Slice least(start_key.data(), start_key.size());
69 | leveldb::Slice greatest(end_key.data(), end_key.size());
70 |
71 | // commenting out the line below causes the example to work correctly
72 | db->CompactRange(&least, &greatest);
73 |
74 | // count the keys
75 | leveldb::Iterator* iter = db->NewIterator(leveldb::ReadOptions());
76 | size_t num_keys = 0;
77 | for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
78 | num_keys++;
79 | }
80 | delete iter;
81 | ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys";
82 |
83 | // close database
84 | delete db;
85 | DestroyDB(dbpath, leveldb::Options());
86 | }
87 |
88 | } // anonymous namespace
89 |
90 | int main(int argc, char** argv) {
91 | return leveldb::test::RunAllTests();
92 | }
93 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/issues/issue200_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | // Test for issue 200: when iterator switches direction from backward
6 | // to forward, the current key can be yielded unexpectedly if a new
7 | // mutation has been added just before the current key.
8 |
9 | #include "hyperleveldb/db.h"
10 | #include "util/testharness.h"
11 |
12 | namespace leveldb {
13 |
14 | class Issue200 { };
15 |
16 | TEST(Issue200, Test) {
17 | // Get rid of any state from an old run.
18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test";
19 | DestroyDB(dbpath, Options());
20 |
21 | DB *db;
22 | Options options;
23 | options.create_if_missing = true;
24 | ASSERT_OK(DB::Open(options, dbpath, &db));
25 |
26 | WriteOptions write_options;
27 | ASSERT_OK(db->Put(write_options, "1", "b"));
28 | ASSERT_OK(db->Put(write_options, "2", "c"));
29 | ASSERT_OK(db->Put(write_options, "3", "d"));
30 | ASSERT_OK(db->Put(write_options, "4", "e"));
31 | ASSERT_OK(db->Put(write_options, "5", "f"));
32 |
33 | ReadOptions read_options;
34 | Iterator *iter = db->NewIterator(read_options);
35 |
36 | // Add an element that should not be reflected in the iterator.
37 | ASSERT_OK(db->Put(write_options, "25", "cd"));
38 |
39 | iter->Seek("5");
40 | ASSERT_EQ(iter->key().ToString(), "5");
41 | iter->Prev();
42 | ASSERT_EQ(iter->key().ToString(), "4");
43 | iter->Prev();
44 | ASSERT_EQ(iter->key().ToString(), "3");
45 | iter->Next();
46 | ASSERT_EQ(iter->key().ToString(), "4");
47 | iter->Next();
48 | ASSERT_EQ(iter->key().ToString(), "5");
49 |
50 | delete iter;
51 | delete db;
52 | DestroyDB(dbpath, options);
53 | }
54 |
55 | } // namespace leveldb
56 |
57 | int main(int argc, char** argv) {
58 | return leveldb::test::RunAllTests();
59 | }
60 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/libhyperleveldb.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: HyperLevelDB
7 | Description: A fast and lightweight key-value storage library
8 | Version: @VERSION@
9 |
10 | Requires:
11 | Libs: -L${libdir} -lhyperleveldb
12 | Cflags: -I${includedir}
13 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/port/README:
--------------------------------------------------------------------------------
1 | This directory contains interfaces and implementations that isolate the
2 | rest of the package from platform details.
3 |
4 | Code in the rest of the package includes "port.h" from this directory.
5 | "port.h" in turn includes a platform specific "port_.h" file
6 | that provides the platform specific implementation.
7 |
8 | See port_posix.h for an example of what must be provided in a platform
9 | specific header file.
10 |
11 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/port/port.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_
6 | #define STORAGE_LEVELDB_PORT_PORT_H_
7 |
8 | #include
9 |
10 | // Include the appropriate platform specific file below. If you are
11 | // porting to a new platform, see "port_example.h" for documentation
12 | // of what the new port_.h file must provide.
13 | #if defined(LEVELDB_PLATFORM_POSIX)
14 | # include "port/port_posix.h"
15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM)
16 | # include "port/port_chromium.h"
17 | #endif
18 |
19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_
20 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/port/port_posix.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "port/port_posix.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include "util/logging.h"
11 |
12 | namespace leveldb {
13 | namespace port {
14 |
15 | static void PthreadCall(const char* label, int result) {
16 | if (result != 0) {
17 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
18 | abort();
19 | }
20 | }
21 |
22 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
23 |
24 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
25 |
26 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
27 |
28 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }
29 |
30 | CondVar::CondVar(Mutex* mu)
31 | : mu_(mu) {
32 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL));
33 | }
34 |
35 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); }
36 |
37 | void CondVar::Wait() {
38 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
39 | }
40 |
41 | void CondVar::Signal() {
42 | PthreadCall("signal", pthread_cond_signal(&cv_));
43 | }
44 |
45 | void CondVar::SignalAll() {
46 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
47 | }
48 |
49 | void InitOnce(OnceType* once, void (*initializer)()) {
50 | PthreadCall("once", pthread_once(once, initializer));
51 | }
52 |
53 | } // namespace port
54 | } // namespace leveldb
55 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/port/thread_annotations.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H
6 |
7 | // Some environments provide custom macros to aid in static thread-safety
8 | // analysis. Provide empty definitions of such macros unless they are already
9 | // defined.
10 |
11 | #ifndef EXCLUSIVE_LOCKS_REQUIRED
12 | #define EXCLUSIVE_LOCKS_REQUIRED(...)
13 | #endif
14 |
15 | #ifndef SHARED_LOCKS_REQUIRED
16 | #define SHARED_LOCKS_REQUIRED(...)
17 | #endif
18 |
19 | #ifndef LOCKS_EXCLUDED
20 | #define LOCKS_EXCLUDED(...)
21 | #endif
22 |
23 | #ifndef LOCK_RETURNED
24 | #define LOCK_RETURNED(x)
25 | #endif
26 |
27 | #ifndef LOCKABLE
28 | #define LOCKABLE
29 | #endif
30 |
31 | #ifndef SCOPED_LOCKABLE
32 | #define SCOPED_LOCKABLE
33 | #endif
34 |
35 | #ifndef EXCLUSIVE_LOCK_FUNCTION
36 | #define EXCLUSIVE_LOCK_FUNCTION(...)
37 | #endif
38 |
39 | #ifndef SHARED_LOCK_FUNCTION
40 | #define SHARED_LOCK_FUNCTION(...)
41 | #endif
42 |
43 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION
44 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...)
45 | #endif
46 |
47 | #ifndef SHARED_TRYLOCK_FUNCTION
48 | #define SHARED_TRYLOCK_FUNCTION(...)
49 | #endif
50 |
51 | #ifndef UNLOCK_FUNCTION
52 | #define UNLOCK_FUNCTION(...)
53 | #endif
54 |
55 | #ifndef NO_THREAD_SAFETY_ANALYSIS
56 | #define NO_THREAD_SAFETY_ANALYSIS
57 | #endif
58 |
59 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H
60 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/port/win/stdint.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | // MSVC didn't ship with this file until the 2010 version.
6 |
7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_
8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_
9 |
10 | #if !defined(_MSC_VER)
11 | #error This file should only be included when compiling with MSVC.
12 | #endif
13 |
14 | // Define C99 equivalent types.
15 | typedef signed char int8_t;
16 | typedef signed short int16_t;
17 | typedef signed int int32_t;
18 | typedef signed long long int64_t;
19 | typedef unsigned char uint8_t;
20 | typedef unsigned short uint16_t;
21 | typedef unsigned int uint32_t;
22 | typedef unsigned long long uint64_t;
23 |
24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_
25 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/block.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_
6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_
7 |
8 | #include
9 | #include
10 | #include "hyperleveldb/iterator.h"
11 |
12 | namespace leveldb {
13 |
14 | struct BlockContents;
15 | class Comparator;
16 |
17 | class Block {
18 | public:
19 | // Initialize the block with the specified contents.
20 | explicit Block(const BlockContents& contents);
21 |
22 | ~Block();
23 |
24 | size_t size() const { return size_; }
25 | Iterator* NewIterator(const Comparator* comparator);
26 |
27 | private:
28 | uint32_t NumRestarts() const;
29 |
30 | const char* data_;
31 | size_t size_;
32 | uint32_t restart_offset_; // Offset in data_ of restart array
33 | bool owned_; // Block owns data_[]
34 |
35 | // No copying allowed
36 | Block(const Block&);
37 | void operator=(const Block&);
38 |
39 | class Iter;
40 | };
41 |
42 | } // namespace leveldb
43 |
44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_
45 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/block_builder.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
7 |
8 | #include
9 |
10 | #include
11 | #include "hyperleveldb/slice.h"
12 |
13 | namespace leveldb {
14 |
15 | struct Options;
16 |
17 | class BlockBuilder {
18 | public:
19 | explicit BlockBuilder(const Options* options);
20 |
21 | // Reset the contents as if the BlockBuilder was just constructed.
22 | void Reset();
23 |
24 | // REQUIRES: Finish() has not been callled since the last call to Reset().
25 | // REQUIRES: key is larger than any previously added key
26 | void Add(const Slice& key, const Slice& value);
27 |
28 | // Finish building the block and return a slice that refers to the
29 | // block contents. The returned slice will remain valid for the
30 | // lifetime of this builder or until Reset() is called.
31 | Slice Finish();
32 |
33 | // Returns an estimate of the current (uncompressed) size of the block
34 | // we are building.
35 | size_t CurrentSizeEstimate() const;
36 |
37 | // Return true iff no entries have been added since the last Reset()
38 | bool empty() const {
39 | return buffer_.empty();
40 | }
41 |
42 | private:
43 | const Options* options_;
44 | std::string buffer_; // Destination buffer
45 | std::vector restarts_; // Restart points
46 | int counter_; // Number of entries emitted since restart
47 | bool finished_; // Has Finish() been called?
48 | std::string last_key_;
49 |
50 | // No copying allowed
51 | BlockBuilder(const BlockBuilder&);
52 | void operator=(const BlockBuilder&);
53 | };
54 |
55 | } // namespace leveldb
56 |
57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
58 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/filter_block.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // A filter block is stored near the end of a Table file. It contains
6 | // filters (e.g., bloom filters) for all data blocks in the table combined
7 | // into a single filter block.
8 |
9 | #ifndef STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_
10 | #define STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include "hyperleveldb/slice.h"
17 | #include "util/hash.h"
18 |
19 | namespace leveldb {
20 |
21 | class FilterPolicy;
22 |
23 | // A FilterBlockBuilder is used to construct all of the filters for a
24 | // particular Table. It generates a single string which is stored as
25 | // a special block in the Table.
26 | //
27 | // The sequence of calls to FilterBlockBuilder must match the regexp:
28 | // (StartBlock AddKey*)* Finish
29 | class FilterBlockBuilder {
30 | public:
31 | explicit FilterBlockBuilder(const FilterPolicy*);
32 |
33 | void StartBlock(uint64_t block_offset);
34 | void AddKey(const Slice& key);
35 | Slice Finish();
36 |
37 | private:
38 | void GenerateFilter();
39 |
40 | const FilterPolicy* policy_;
41 | std::string keys_; // Flattened key contents
42 | std::vector start_; // Starting index in keys_ of each key
43 | std::string result_; // Filter data computed so far
44 | std::vector tmp_keys_; // policy_->CreateFilter() argument
45 | std::vector filter_offsets_;
46 |
47 | // No copying allowed
48 | FilterBlockBuilder(const FilterBlockBuilder&);
49 | void operator=(const FilterBlockBuilder&);
50 | };
51 |
52 | class FilterBlockReader {
53 | public:
54 | // REQUIRES: "contents" and *policy must stay live while *this is live.
55 | FilterBlockReader(const FilterPolicy* policy, const Slice& contents);
56 | bool KeyMayMatch(uint64_t block_offset, const Slice& key);
57 |
58 | private:
59 | const FilterPolicy* policy_;
60 | const char* data_; // Pointer to filter data (at block-start)
61 | const char* offset_; // Pointer to beginning of offset array (at block-end)
62 | size_t num_; // Number of entries in offset array
63 | size_t base_lg_; // Encoding parameter (see kFilterBaseLg in .cc file)
64 | };
65 |
66 | }
67 |
68 | #endif // STORAGE_LEVELDB_TABLE_FILTER_BLOCK_H_
69 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/iterator.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/iterator.h"
6 |
7 | namespace leveldb {
8 |
9 | Iterator::Iterator() {
10 | cleanup_.function = NULL;
11 | cleanup_.next = NULL;
12 | }
13 |
14 | Iterator::~Iterator() {
15 | if (cleanup_.function != NULL) {
16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
17 | for (Cleanup* c = cleanup_.next; c != NULL; ) {
18 | (*c->function)(c->arg1, c->arg2);
19 | Cleanup* next = c->next;
20 | delete c;
21 | c = next;
22 | }
23 | }
24 | }
25 |
26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
27 | assert(func != NULL);
28 | Cleanup* c;
29 | if (cleanup_.function == NULL) {
30 | c = &cleanup_;
31 | } else {
32 | c = new Cleanup;
33 | c->next = cleanup_.next;
34 | cleanup_.next = c;
35 | }
36 | c->function = func;
37 | c->arg1 = arg1;
38 | c->arg2 = arg2;
39 | }
40 |
41 | namespace {
42 | class EmptyIterator : public Iterator {
43 | public:
44 | EmptyIterator(const Status& s) : status_(s) { }
45 | virtual bool Valid() const { return false; }
46 | virtual void Seek(const Slice& target) { }
47 | virtual void SeekToFirst() { }
48 | virtual void SeekToLast() { }
49 | virtual void Next() { assert(false); }
50 | virtual void Prev() { assert(false); }
51 | Slice key() const { assert(false); return Slice(); }
52 | Slice value() const { assert(false); return Slice(); }
53 | virtual Status status() const { return status_; }
54 | private:
55 | Status status_;
56 | };
57 | } // namespace
58 |
59 | Iterator* NewEmptyIterator() {
60 | return new EmptyIterator(Status::OK());
61 | }
62 |
63 | Iterator* NewErrorIterator(const Status& status) {
64 | return new EmptyIterator(status);
65 | }
66 |
67 | } // namespace leveldb
68 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/iterator_wrapper.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
7 |
8 | namespace leveldb {
9 |
10 | // A internal wrapper class with an interface similar to Iterator that
11 | // caches the valid() and key() results for an underlying iterator.
12 | // This can help avoid virtual function calls and also gives better
13 | // cache locality.
14 | class IteratorWrapper {
15 | public:
16 | IteratorWrapper(): iter_(NULL), valid_(false) { }
17 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) {
18 | Set(iter);
19 | }
20 | ~IteratorWrapper() { delete iter_; }
21 | Iterator* iter() const { return iter_; }
22 |
23 | // Takes ownership of "iter" and will delete it when destroyed, or
24 | // when Set() is invoked again.
25 | void Set(Iterator* iter) {
26 | delete iter_;
27 | iter_ = iter;
28 | if (iter_ == NULL) {
29 | valid_ = false;
30 | } else {
31 | Update();
32 | }
33 | }
34 |
35 |
36 | // Iterator interface methods
37 | bool Valid() const { return valid_; }
38 | Slice key() const { assert(Valid()); return key_; }
39 | Slice value() const { assert(Valid()); return iter_->value(); }
40 | // Methods below require iter() != NULL
41 | Status status() const { assert(iter_); return iter_->status(); }
42 | void Next() { assert(iter_); iter_->Next(); Update(); }
43 | void Prev() { assert(iter_); iter_->Prev(); Update(); }
44 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); }
45 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); }
46 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); }
47 |
48 | private:
49 | void Update() {
50 | valid_ = iter_->Valid();
51 | if (valid_) {
52 | key_ = iter_->key();
53 | }
54 | }
55 |
56 | Iterator* iter_;
57 | bool valid_;
58 | Slice key_;
59 | };
60 |
61 | } // namespace leveldb
62 |
63 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
64 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/merger.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_
6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_
7 |
8 | namespace leveldb {
9 |
10 | class Comparator;
11 | class Iterator;
12 |
13 | // Return an iterator that provided the union of the data in
14 | // children[0,n-1]. Takes ownership of the child iterators and
15 | // will delete them when the result iterator is deleted.
16 | //
17 | // The result does no duplicate suppression. I.e., if a particular
18 | // key is present in K child iterators, it will be yielded K times.
19 | //
20 | // REQUIRES: n >= 0
21 | extern Iterator* NewMergingIterator(
22 | const Comparator* comparator, Iterator** children, int n);
23 |
24 | } // namespace leveldb
25 |
26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_
27 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/table/two_level_iterator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_
6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_
7 |
8 | #include "hyperleveldb/iterator.h"
9 |
10 | namespace leveldb {
11 |
12 | struct ReadOptions;
13 |
14 | // Return a new two level iterator. A two-level iterator contains an
15 | // index iterator whose values point to a sequence of blocks where
16 | // each block is itself a sequence of key,value pairs. The returned
17 | // two-level iterator yields the concatenation of all key/value pairs
18 | // in the sequence of blocks. Takes ownership of "index_iter" and
19 | // will delete it when no longer needed.
20 | //
21 | // Uses a supplied function to convert an index_iter value into
22 | // an iterator over the contents of the corresponding block.
23 | extern Iterator* NewTwoLevelIterator(
24 | Iterator* index_iter,
25 | Iterator* (*block_function)(
26 | void* arg,
27 | const ReadOptions& options,
28 | const Slice& index_value),
29 | void* arg,
30 | const ReadOptions& options);
31 |
32 | } // namespace leveldb
33 |
34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_
35 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/arena.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/arena.h"
6 | #include
7 |
8 | namespace leveldb {
9 |
10 | static const int kBlockSize = 4096;
11 |
12 | Arena::Arena() {
13 | blocks_memory_ = 0;
14 | alloc_ptr_ = NULL; // First allocation will allocate a block
15 | alloc_bytes_remaining_ = 0;
16 | }
17 |
18 | Arena::~Arena() {
19 | for (size_t i = 0; i < blocks_.size(); i++) {
20 | delete[] blocks_[i];
21 | }
22 | }
23 |
24 | char* Arena::AllocateFallback(size_t bytes) {
25 | if (bytes > kBlockSize / 4) {
26 | // Object is more than a quarter of our block size. Allocate it separately
27 | // to avoid wasting too much space in leftover bytes.
28 | char* result = AllocateNewBlock(bytes);
29 | return result;
30 | }
31 |
32 | // We waste the remaining space in the current block.
33 | alloc_ptr_ = AllocateNewBlock(kBlockSize);
34 | alloc_bytes_remaining_ = kBlockSize;
35 |
36 | char* result = alloc_ptr_;
37 | alloc_ptr_ += bytes;
38 | alloc_bytes_remaining_ -= bytes;
39 | return result;
40 | }
41 |
42 | char* Arena::AllocateAligned(size_t bytes) {
43 | const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8;
44 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2
45 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1);
46 | size_t slop = (current_mod == 0 ? 0 : align - current_mod);
47 | size_t needed = bytes + slop;
48 | char* result;
49 | if (needed <= alloc_bytes_remaining_) {
50 | result = alloc_ptr_ + slop;
51 | alloc_ptr_ += needed;
52 | alloc_bytes_remaining_ -= needed;
53 | } else {
54 | // AllocateFallback always returned aligned memory
55 | result = AllocateFallback(bytes);
56 | }
57 | assert((reinterpret_cast(result) & (align-1)) == 0);
58 | return result;
59 | }
60 |
61 | char* Arena::AllocateNewBlock(size_t block_bytes) {
62 | char* result = new char[block_bytes];
63 | blocks_memory_ += block_bytes;
64 | blocks_.push_back(result);
65 | return result;
66 | }
67 |
68 | } // namespace leveldb
69 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/arena.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_
6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | namespace leveldb {
14 |
15 | class Arena {
16 | public:
17 | Arena();
18 | ~Arena();
19 |
20 | // Return a pointer to a newly allocated memory block of "bytes" bytes.
21 | char* Allocate(size_t bytes);
22 |
23 | // Allocate memory with the normal alignment guarantees provided by malloc
24 | char* AllocateAligned(size_t bytes);
25 |
26 | // Returns an estimate of the total memory usage of data allocated
27 | // by the arena (including space allocated but not yet used for user
28 | // allocations).
29 | size_t MemoryUsage() const {
30 | return blocks_memory_ + blocks_.capacity() * sizeof(char*);
31 | }
32 |
33 | private:
34 | char* AllocateFallback(size_t bytes);
35 | char* AllocateNewBlock(size_t block_bytes);
36 |
37 | // Allocation state
38 | char* alloc_ptr_;
39 | size_t alloc_bytes_remaining_;
40 |
41 | // Array of new[] allocated memory blocks
42 | std::vector blocks_;
43 |
44 | // Bytes of memory in blocks allocated so far
45 | size_t blocks_memory_;
46 |
47 | // No copying allowed
48 | Arena(const Arena&);
49 | void operator=(const Arena&);
50 | };
51 |
52 | inline char* Arena::Allocate(size_t bytes) {
53 | // The semantics of what to return are a bit messy if we allow
54 | // 0-byte allocations, so we disallow them here (we don't need
55 | // them for our internal use).
56 | assert(bytes > 0);
57 | if (bytes <= alloc_bytes_remaining_) {
58 | char* result = alloc_ptr_;
59 | alloc_ptr_ += bytes;
60 | alloc_bytes_remaining_ -= bytes;
61 | return result;
62 | }
63 | return AllocateFallback(bytes);
64 | }
65 |
66 | } // namespace leveldb
67 |
68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_
69 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/arena_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/arena.h"
6 |
7 | #include "util/random.h"
8 | #include "util/testharness.h"
9 |
10 | namespace leveldb {
11 |
12 | class ArenaTest { };
13 |
14 | TEST(ArenaTest, Empty) {
15 | Arena arena;
16 | }
17 |
18 | TEST(ArenaTest, Simple) {
19 | std::vector > allocated;
20 | Arena arena;
21 | const int N = 100000;
22 | size_t bytes = 0;
23 | Random rnd(301);
24 | for (int i = 0; i < N; i++) {
25 | size_t s;
26 | if (i % (N / 10) == 0) {
27 | s = i;
28 | } else {
29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) :
30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20));
31 | }
32 | if (s == 0) {
33 | // Our arena disallows size 0 allocations.
34 | s = 1;
35 | }
36 | char* r;
37 | if (rnd.OneIn(10)) {
38 | r = arena.AllocateAligned(s);
39 | } else {
40 | r = arena.Allocate(s);
41 | }
42 |
43 | for (int b = 0; b < s; b++) {
44 | // Fill the "i"th allocation with a known bit pattern
45 | r[b] = i % 256;
46 | }
47 | bytes += s;
48 | allocated.push_back(std::make_pair(s, r));
49 | ASSERT_GE(arena.MemoryUsage(), bytes);
50 | if (i > N/10) {
51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10);
52 | }
53 | }
54 | for (int i = 0; i < allocated.size(); i++) {
55 | size_t num_bytes = allocated[i].first;
56 | const char* p = allocated[i].second;
57 | for (int b = 0; b < num_bytes; b++) {
58 | // Check the "i"th allocation for the known bit pattern
59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256);
60 | }
61 | }
62 | }
63 |
64 | } // namespace leveldb
65 |
66 | int main(int argc, char** argv) {
67 | return leveldb::test::RunAllTests();
68 | }
69 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/bloom.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/filter_policy.h"
6 |
7 | #include "hyperleveldb/slice.h"
8 | #include "util/hash.h"
9 |
10 | namespace leveldb {
11 |
12 | namespace {
13 | static uint32_t BloomHash(const Slice& key) {
14 | return Hash(key.data(), key.size(), 0xbc9f1d34);
15 | }
16 |
17 | class BloomFilterPolicy : public FilterPolicy {
18 | private:
19 | size_t bits_per_key_;
20 | size_t k_;
21 |
22 | public:
23 | explicit BloomFilterPolicy(int bits_per_key)
24 | : bits_per_key_(bits_per_key) {
25 | // We intentionally round down to reduce probing cost a little bit
26 | k_ = static_cast(bits_per_key * 0.69); // 0.69 =~ ln(2)
27 | if (k_ < 1) k_ = 1;
28 | if (k_ > 30) k_ = 30;
29 | }
30 |
31 | virtual const char* Name() const {
32 | return "leveldb.BuiltinBloomFilter";
33 | }
34 |
35 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const {
36 | // Compute bloom filter size (in both bits and bytes)
37 | size_t bits = n * bits_per_key_;
38 |
39 | // For small n, we can see a very high false positive rate. Fix it
40 | // by enforcing a minimum bloom filter length.
41 | if (bits < 64) bits = 64;
42 |
43 | size_t bytes = (bits + 7) / 8;
44 | bits = bytes * 8;
45 |
46 | const size_t init_size = dst->size();
47 | dst->resize(init_size + bytes, 0);
48 | dst->push_back(static_cast(k_)); // Remember # of probes in filter
49 | char* array = &(*dst)[init_size];
50 | for (size_t i = 0; i < n; i++) {
51 | // Use double-hashing to generate a sequence of hash values.
52 | // See analysis in [Kirsch,Mitzenmacher 2006].
53 | uint32_t h = BloomHash(keys[i]);
54 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits
55 | for (size_t j = 0; j < k_; j++) {
56 | const uint32_t bitpos = h % bits;
57 | array[bitpos/8] |= (1 << (bitpos % 8));
58 | h += delta;
59 | }
60 | }
61 | }
62 |
63 | virtual bool KeyMayMatch(const Slice& key, const Slice& bloom_filter) const {
64 | const size_t len = bloom_filter.size();
65 | if (len < 2) return false;
66 |
67 | const char* array = bloom_filter.data();
68 | const size_t bits = (len - 1) * 8;
69 |
70 | // Use the encoded k so that we can read filters generated by
71 | // bloom filters created using different parameters.
72 | const size_t k = array[len-1];
73 | if (k > 30) {
74 | // Reserved for potentially new encodings for short bloom filters.
75 | // Consider it a match.
76 | return true;
77 | }
78 |
79 | uint32_t h = BloomHash(key);
80 | const uint32_t delta = (h >> 17) | (h << 15); // Rotate right 17 bits
81 | for (size_t j = 0; j < k; j++) {
82 | const uint32_t bitpos = h % bits;
83 | if ((array[bitpos/8] & (1 << (bitpos % 8))) == 0) return false;
84 | h += delta;
85 | }
86 | return true;
87 | }
88 | };
89 | }
90 |
91 | const FilterPolicy* NewBloomFilterPolicy(int bits_per_key) {
92 | return new BloomFilterPolicy(bits_per_key);
93 | }
94 |
95 | } // namespace leveldb
96 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/comparator.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include
6 | #include
7 | #include "hyperleveldb/comparator.h"
8 | #include "hyperleveldb/slice.h"
9 | #include "port/port.h"
10 | #include "util/coding.h"
11 | #include "util/logging.h"
12 |
13 | namespace leveldb {
14 |
15 | Comparator::~Comparator() { }
16 |
17 | uint64_t Comparator::KeyNum(const Slice& key) const {
18 | return 0;
19 | }
20 |
21 | namespace {
22 | class BytewiseComparatorImpl : public Comparator {
23 | public:
24 | BytewiseComparatorImpl() { }
25 |
26 | virtual const char* Name() const {
27 | return "leveldb.BytewiseComparator";
28 | }
29 |
30 | virtual int Compare(const Slice& a, const Slice& b) const {
31 | return a.compare(b);
32 | }
33 |
34 | virtual void FindShortestSeparator(
35 | std::string* start,
36 | const Slice& limit) const {
37 | // Find length of common prefix
38 | size_t min_length = std::min(start->size(), limit.size());
39 | size_t diff_index = 0;
40 | while ((diff_index < min_length) &&
41 | ((*start)[diff_index] == limit[diff_index])) {
42 | diff_index++;
43 | }
44 |
45 | if (diff_index >= min_length) {
46 | // Do not shorten if one string is a prefix of the other
47 | } else {
48 | uint8_t diff_byte = static_cast((*start)[diff_index]);
49 | if (diff_byte < static_cast(0xff) &&
50 | diff_byte + 1 < static_cast(limit[diff_index])) {
51 | (*start)[diff_index]++;
52 | start->resize(diff_index + 1);
53 | assert(Compare(*start, limit) < 0);
54 | }
55 | }
56 | }
57 |
58 | virtual void FindShortSuccessor(std::string* key) const {
59 | // Find first character that can be incremented
60 | size_t n = key->size();
61 | for (size_t i = 0; i < n; i++) {
62 | const uint8_t byte = (*key)[i];
63 | if (byte != static_cast(0xff)) {
64 | (*key)[i] = byte + 1;
65 | key->resize(i+1);
66 | return;
67 | }
68 | }
69 | // *key is a run of 0xffs. Leave it alone.
70 | }
71 |
72 | virtual uint64_t KeyNum(const Slice& key) const {
73 | unsigned char buf[sizeof(uint64_t)];
74 | memset(buf, 0, sizeof(buf));
75 | memmove(buf, key.data(), std::min(key.size(), sizeof(uint64_t)));
76 | uint64_t number;
77 | number = static_cast(buf[0]) << 56
78 | | static_cast(buf[1]) << 48
79 | | static_cast(buf[2]) << 40
80 | | static_cast(buf[3]) << 32
81 | | static_cast(buf[4]) << 24
82 | | static_cast(buf[5]) << 16
83 | | static_cast(buf[6]) << 8
84 | | static_cast(buf[7]);
85 | return number;
86 | }
87 | };
88 | } // namespace
89 |
90 | static port::OnceType once = LEVELDB_ONCE_INIT;
91 | static const Comparator* bytewise;
92 |
93 | static void InitModule() {
94 | bytewise = new BytewiseComparatorImpl;
95 | }
96 |
97 | const Comparator* BytewiseComparator() {
98 | port::InitOnce(&once, InitModule);
99 | return bytewise;
100 | }
101 |
102 | } // namespace leveldb
103 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/crc32c.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_
6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_
7 |
8 | #include
9 | #include
10 |
11 | namespace leveldb {
12 | namespace crc32c {
13 |
14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the
15 | // crc32c of some string A. Extend() is often used to maintain the
16 | // crc32c of a stream of data.
17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n);
18 |
19 | // Return the crc32c of data[0,n-1]
20 | inline uint32_t Value(const char* data, size_t n) {
21 | return Extend(0, data, n);
22 | }
23 |
24 | static const uint32_t kMaskDelta = 0xa282ead8ul;
25 |
26 | // Return a masked representation of crc.
27 | //
28 | // Motivation: it is problematic to compute the CRC of a string that
29 | // contains embedded CRCs. Therefore we recommend that CRCs stored
30 | // somewhere (e.g., in files) should be masked before being stored.
31 | inline uint32_t Mask(uint32_t crc) {
32 | // Rotate right by 15 bits and add a constant.
33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta;
34 | }
35 |
36 | // Return the crc whose masked representation is masked_crc.
37 | inline uint32_t Unmask(uint32_t masked_crc) {
38 | uint32_t rot = masked_crc - kMaskDelta;
39 | return ((rot >> 17) | (rot << 15));
40 | }
41 |
42 | } // namespace crc32c
43 | } // namespace leveldb
44 |
45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_
46 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/crc32c_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/crc32c.h"
6 | #include "util/testharness.h"
7 |
8 | namespace leveldb {
9 | namespace crc32c {
10 |
11 | class CRC { };
12 |
13 | TEST(CRC, StandardResults) {
14 | // From rfc3720 section B.4.
15 | char buf[32];
16 |
17 | memset(buf, 0, sizeof(buf));
18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf)));
19 |
20 | memset(buf, 0xff, sizeof(buf));
21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf)));
22 |
23 | for (int i = 0; i < 32; i++) {
24 | buf[i] = i;
25 | }
26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf)));
27 |
28 | for (int i = 0; i < 32; i++) {
29 | buf[i] = 31 - i;
30 | }
31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf)));
32 |
33 | unsigned char data[48] = {
34 | 0x01, 0xc0, 0x00, 0x00,
35 | 0x00, 0x00, 0x00, 0x00,
36 | 0x00, 0x00, 0x00, 0x00,
37 | 0x00, 0x00, 0x00, 0x00,
38 | 0x14, 0x00, 0x00, 0x00,
39 | 0x00, 0x00, 0x04, 0x00,
40 | 0x00, 0x00, 0x00, 0x14,
41 | 0x00, 0x00, 0x00, 0x18,
42 | 0x28, 0x00, 0x00, 0x00,
43 | 0x00, 0x00, 0x00, 0x00,
44 | 0x02, 0x00, 0x00, 0x00,
45 | 0x00, 0x00, 0x00, 0x00,
46 | };
47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data)));
48 | }
49 |
50 | TEST(CRC, Values) {
51 | ASSERT_NE(Value("a", 1), Value("foo", 3));
52 | }
53 |
54 | TEST(CRC, Extend) {
55 | ASSERT_EQ(Value("hello world", 11),
56 | Extend(Value("hello ", 6), "world", 5));
57 | }
58 |
59 | TEST(CRC, Mask) {
60 | uint32_t crc = Value("foo", 3);
61 | ASSERT_NE(crc, Mask(crc));
62 | ASSERT_NE(crc, Mask(Mask(crc)));
63 | ASSERT_EQ(crc, Unmask(Mask(crc)));
64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc)))));
65 | }
66 |
67 | } // namespace crc32c
68 | } // namespace leveldb
69 |
70 | int main(int argc, char** argv) {
71 | return leveldb::test::RunAllTests();
72 | }
73 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/env.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/env.h"
6 |
7 | namespace leveldb {
8 |
9 | Env::~Env() {
10 | }
11 |
12 | SequentialFile::~SequentialFile() {
13 | }
14 |
15 | RandomAccessFile::~RandomAccessFile() {
16 | }
17 |
18 | WritableFile::~WritableFile() {
19 | }
20 |
21 | Logger::~Logger() {
22 | }
23 |
24 | FileLock::~FileLock() {
25 | }
26 |
27 | void Log(Logger* info_log, const char* format, ...) {
28 | if (info_log != NULL) {
29 | va_list ap;
30 | va_start(ap, format);
31 | info_log->Logv(format, ap);
32 | va_end(ap);
33 | }
34 | }
35 |
36 | static Status DoWriteStringToFile(Env* env, const Slice& data,
37 | const std::string& fname,
38 | bool should_sync) {
39 | WritableFile* file;
40 | Status s = env->NewWritableFile(fname, &file);
41 | if (!s.ok()) {
42 | return s;
43 | }
44 | s = file->Append(data);
45 | if (s.ok() && should_sync) {
46 | s = file->Sync();
47 | }
48 | if (s.ok()) {
49 | s = file->Close();
50 | }
51 | delete file; // Will auto-close if we did not close above
52 | if (!s.ok()) {
53 | env->DeleteFile(fname);
54 | }
55 | return s;
56 | }
57 |
58 | Status WriteStringToFile(Env* env, const Slice& data,
59 | const std::string& fname) {
60 | return DoWriteStringToFile(env, data, fname, false);
61 | }
62 |
63 | Status WriteStringToFileSync(Env* env, const Slice& data,
64 | const std::string& fname) {
65 | return DoWriteStringToFile(env, data, fname, true);
66 | }
67 |
68 | Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
69 | data->clear();
70 | SequentialFile* file;
71 | Status s = env->NewSequentialFile(fname, &file);
72 | if (!s.ok()) {
73 | return s;
74 | }
75 | static const int kBufferSize = 8192;
76 | char* space = new char[kBufferSize];
77 | while (true) {
78 | Slice fragment;
79 | s = file->Read(kBufferSize, &fragment, space);
80 | if (!s.ok()) {
81 | break;
82 | }
83 | data->append(fragment.data(), fragment.size());
84 | if (fragment.empty()) {
85 | break;
86 | }
87 | }
88 | delete[] space;
89 | delete file;
90 | return s;
91 | }
92 |
93 | EnvWrapper::~EnvWrapper() {
94 | }
95 |
96 | } // namespace leveldb
97 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/env_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/env.h"
6 |
7 | #include "port/port.h"
8 | #include "util/testharness.h"
9 |
10 | namespace leveldb {
11 |
12 | static const int kDelayMicros = 100000;
13 |
14 | class EnvPosixTest {
15 | private:
16 | port::Mutex mu_;
17 | std::string events_;
18 |
19 | public:
20 | Env* env_;
21 | EnvPosixTest() : env_(Env::Default()) { }
22 | };
23 |
24 | static void SetBool(void* ptr) {
25 | reinterpret_cast(ptr)->NoBarrier_Store(ptr);
26 | }
27 |
28 | TEST(EnvPosixTest, RunImmediately) {
29 | port::AtomicPointer called (NULL);
30 | env_->Schedule(&SetBool, &called);
31 | Env::Default()->SleepForMicroseconds(kDelayMicros);
32 | ASSERT_TRUE(called.NoBarrier_Load() != NULL);
33 | }
34 |
35 | TEST(EnvPosixTest, RunMany) {
36 | port::AtomicPointer last_id (NULL);
37 |
38 | struct CB {
39 | port::AtomicPointer* last_id_ptr; // Pointer to shared slot
40 | uintptr_t id; // Order# for the execution of this callback
41 |
42 | CB(port::AtomicPointer* p, int i) : last_id_ptr(p), id(i) { }
43 |
44 | static void Run(void* v) {
45 | CB* cb = reinterpret_cast(v);
46 | void* cur = cb->last_id_ptr->NoBarrier_Load();
47 | ASSERT_EQ(cb->id-1, reinterpret_cast(cur));
48 | cb->last_id_ptr->Release_Store(reinterpret_cast(cb->id));
49 | }
50 | };
51 |
52 | // Schedule in different order than start time
53 | CB cb1(&last_id, 1);
54 | CB cb2(&last_id, 2);
55 | CB cb3(&last_id, 3);
56 | CB cb4(&last_id, 4);
57 | env_->Schedule(&CB::Run, &cb1);
58 | env_->Schedule(&CB::Run, &cb2);
59 | env_->Schedule(&CB::Run, &cb3);
60 | env_->Schedule(&CB::Run, &cb4);
61 |
62 | Env::Default()->SleepForMicroseconds(kDelayMicros);
63 | void* cur = last_id.Acquire_Load();
64 | ASSERT_EQ(4, reinterpret_cast(cur));
65 | }
66 |
67 | struct State {
68 | port::Mutex mu;
69 | int val;
70 | int num_running;
71 | };
72 |
73 | static void ThreadBody(void* arg) {
74 | State* s = reinterpret_cast(arg);
75 | s->mu.Lock();
76 | s->val += 1;
77 | s->num_running -= 1;
78 | s->mu.Unlock();
79 | }
80 |
81 | TEST(EnvPosixTest, StartThread) {
82 | State state;
83 | state.val = 0;
84 | state.num_running = 3;
85 | for (int i = 0; i < 3; i++) {
86 | env_->StartThread(&ThreadBody, &state);
87 | }
88 | while (true) {
89 | state.mu.Lock();
90 | int num = state.num_running;
91 | state.mu.Unlock();
92 | if (num == 0) {
93 | break;
94 | }
95 | Env::Default()->SleepForMicroseconds(kDelayMicros);
96 | }
97 | ASSERT_EQ(state.val, 3);
98 | }
99 |
100 | } // namespace leveldb
101 |
102 | int main(int argc, char** argv) {
103 | return leveldb::test::RunAllTests();
104 | }
105 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/filter_policy.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/filter_policy.h"
6 |
7 | namespace leveldb {
8 |
9 | FilterPolicy::~FilterPolicy() { }
10 |
11 | } // namespace leveldb
12 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/hash.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include
6 | #include "util/coding.h"
7 | #include "util/hash.h"
8 |
9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
10 | // between switch labels. The real definition should be provided externally.
11 | // This one is a fallback version for unsupported compilers.
12 | #ifndef FALLTHROUGH_INTENDED
13 | #define FALLTHROUGH_INTENDED do { } while (0)
14 | #endif
15 |
16 | namespace leveldb {
17 |
18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) {
19 | // Similar to murmur hash
20 | const uint32_t m = 0xc6a4a793;
21 | const uint32_t r = 24;
22 | const char* limit = data + n;
23 | uint32_t h = seed ^ (n * m);
24 |
25 | // Pick up four bytes at a time
26 | while (data + 4 <= limit) {
27 | uint32_t w = DecodeFixed32(data);
28 | data += 4;
29 | h += w;
30 | h *= m;
31 | h ^= (h >> 16);
32 | }
33 |
34 | // Pick up remaining bytes
35 | switch (limit - data) {
36 | case 3:
37 | h += data[2] << 16;
38 | FALLTHROUGH_INTENDED;
39 | case 2:
40 | h += data[1] << 8;
41 | FALLTHROUGH_INTENDED;
42 | case 1:
43 | h += data[0];
44 | h *= m;
45 | h ^= (h >> r);
46 | break;
47 | }
48 | return h;
49 | }
50 |
51 |
52 | } // namespace leveldb
53 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/hash.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // Simple hash function used for internal data structures
6 |
7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_
8 | #define STORAGE_LEVELDB_UTIL_HASH_H_
9 |
10 | #include
11 | #include
12 |
13 | namespace leveldb {
14 |
15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed);
16 |
17 | }
18 |
19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_
20 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/histogram.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
7 |
8 | #include
9 |
10 | namespace leveldb {
11 |
12 | class Histogram {
13 | public:
14 | Histogram() { }
15 | ~Histogram() { }
16 |
17 | void Clear();
18 | void Add(double value);
19 | void Merge(const Histogram& other);
20 |
21 | std::string ToString() const;
22 |
23 | private:
24 | double min_;
25 | double max_;
26 | double num_;
27 | double sum_;
28 | double sum_squares_;
29 |
30 | enum { kNumBuckets = 154 };
31 | static const double kBucketLimit[kNumBuckets];
32 | double buckets_[kNumBuckets];
33 |
34 | double Median() const;
35 | double Percentile(double p) const;
36 | double Average() const;
37 | double StandardDeviation() const;
38 | };
39 |
40 | } // namespace leveldb
41 |
42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_
43 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/logging.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/logging.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "hyperleveldb/env.h"
12 | #include "hyperleveldb/slice.h"
13 |
14 | namespace leveldb {
15 |
16 | void AppendNumberTo(std::string* str, uint64_t num) {
17 | char buf[30];
18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num);
19 | str->append(buf);
20 | }
21 |
22 | void AppendEscapedStringTo(std::string* str, const Slice& value) {
23 | for (size_t i = 0; i < value.size(); i++) {
24 | char c = value[i];
25 | if (c >= ' ' && c <= '~') {
26 | str->push_back(c);
27 | } else {
28 | char buf[10];
29 | snprintf(buf, sizeof(buf), "\\x%02x",
30 | static_cast(c) & 0xff);
31 | str->append(buf);
32 | }
33 | }
34 | }
35 |
36 | std::string NumberToString(uint64_t num) {
37 | std::string r;
38 | AppendNumberTo(&r, num);
39 | return r;
40 | }
41 |
42 | std::string EscapeString(const Slice& value) {
43 | std::string r;
44 | AppendEscapedStringTo(&r, value);
45 | return r;
46 | }
47 |
48 | bool ConsumeChar(Slice* in, char c) {
49 | if (!in->empty() && (*in)[0] == c) {
50 | in->remove_prefix(1);
51 | return true;
52 | } else {
53 | return false;
54 | }
55 | }
56 |
57 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) {
58 | uint64_t v = 0;
59 | int digits = 0;
60 | while (!in->empty()) {
61 | char c = (*in)[0];
62 | if (c >= '0' && c <= '9') {
63 | ++digits;
64 | const int delta = (c - '0');
65 | static const uint64_t kMaxUint64 = ~static_cast(0);
66 | if (v > kMaxUint64/10 ||
67 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
68 | // Overflow
69 | return false;
70 | }
71 | v = (v * 10) + delta;
72 | in->remove_prefix(1);
73 | } else {
74 | break;
75 | }
76 | }
77 | *val = v;
78 | return (digits > 0);
79 | }
80 |
81 | } // namespace leveldb
82 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/logging.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // Must not be included from any .h files to avoid polluting the namespace
6 | // with macros.
7 |
8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_
9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include "port/port.h"
15 |
16 | namespace leveldb {
17 |
18 | class Slice;
19 | class WritableFile;
20 |
21 | // Append a human-readable printout of "num" to *str
22 | extern void AppendNumberTo(std::string* str, uint64_t num);
23 |
24 | // Append a human-readable printout of "value" to *str.
25 | // Escapes any non-printable characters found in "value".
26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value);
27 |
28 | // Return a human-readable printout of "num"
29 | extern std::string NumberToString(uint64_t num);
30 |
31 | // Return a human-readable version of "value".
32 | // Escapes any non-printable characters found in "value".
33 | extern std::string EscapeString(const Slice& value);
34 |
35 | // If *in starts with "c", advances *in past the first character and
36 | // returns true. Otherwise, returns false.
37 | extern bool ConsumeChar(Slice* in, char c);
38 |
39 | // Parse a human-readable number from "*in" into *value. On success,
40 | // advances "*in" past the consumed number and sets "*val" to the
41 | // numeric value. Otherwise, returns false and leaves *in in an
42 | // unspecified state.
43 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val);
44 |
45 | } // namespace leveldb
46 |
47 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_
48 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/mutexlock.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
7 |
8 | #include "port/port.h"
9 | #include "port/thread_annotations.h"
10 |
11 | namespace leveldb {
12 |
13 | // Helper class that locks a mutex on construction and unlocks the mutex when
14 | // the destructor of the MutexLock object is invoked.
15 | //
16 | // Typical usage:
17 | //
18 | // void MyClass::MyMethod() {
19 | // MutexLock l(&mu_); // mu_ is an instance variable
20 | // ... some complex code, possibly with multiple return paths ...
21 | // }
22 |
23 | class SCOPED_LOCKABLE MutexLock {
24 | public:
25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
26 | : mu_(mu) {
27 | this->mu_->Lock();
28 | }
29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); }
30 |
31 | private:
32 | port::Mutex *const mu_;
33 | // No copying allowed
34 | MutexLock(const MutexLock&);
35 | void operator=(const MutexLock&);
36 | };
37 |
38 | } // namespace leveldb
39 |
40 |
41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_
42 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/options.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "hyperleveldb/options.h"
6 |
7 | #include "hyperleveldb/comparator.h"
8 | #include "hyperleveldb/env.h"
9 |
10 | namespace leveldb {
11 |
12 | Options::Options()
13 | : comparator(BytewiseComparator()),
14 | create_if_missing(false),
15 | error_if_exists(false),
16 | paranoid_checks(false),
17 | env(Env::Default()),
18 | info_log(NULL),
19 | write_buffer_size(4<<20),
20 | max_open_files(1000),
21 | block_cache(NULL),
22 | block_size(4096),
23 | block_restart_interval(16),
24 | compression(kSnappyCompression),
25 | filter_policy(NULL),
26 | manual_garbage_collection(false) {
27 | }
28 |
29 |
30 | } // namespace leveldb
31 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/posix_logger.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 | //
5 | // Logger implementation that can be shared by all environments
6 | // where enough posix functionality is available.
7 |
8 | #ifndef STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_
9 | #define STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "hyperleveldb/env.h"
16 |
17 | namespace leveldb {
18 |
19 | class PosixLogger : public Logger {
20 | private:
21 | FILE* file_;
22 | uint64_t (*gettid_)(); // Return the thread id for the current thread
23 | public:
24 | PosixLogger(FILE* f, uint64_t (*gettid)()) : file_(f), gettid_(gettid) { }
25 | virtual ~PosixLogger() {
26 | fclose(file_);
27 | }
28 | virtual void Logv(const char* format, va_list ap) {
29 | const uint64_t thread_id = (*gettid_)();
30 |
31 | // We try twice: the first time with a fixed-size stack allocated buffer,
32 | // and the second time with a much larger dynamically allocated buffer.
33 | char buffer[500];
34 | for (int iter = 0; iter < 2; iter++) {
35 | char* base;
36 | int bufsize;
37 | if (iter == 0) {
38 | bufsize = sizeof(buffer);
39 | base = buffer;
40 | } else {
41 | bufsize = 30000;
42 | base = new char[bufsize];
43 | }
44 | char* p = base;
45 | char* limit = base + bufsize;
46 |
47 | struct timeval now_tv;
48 | gettimeofday(&now_tv, NULL);
49 | const time_t seconds = now_tv.tv_sec;
50 | struct tm t;
51 | localtime_r(&seconds, &t);
52 | p += snprintf(p, limit - p,
53 | "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ",
54 | t.tm_year + 1900,
55 | t.tm_mon + 1,
56 | t.tm_mday,
57 | t.tm_hour,
58 | t.tm_min,
59 | t.tm_sec,
60 | static_cast(now_tv.tv_usec),
61 | static_cast(thread_id));
62 |
63 | // Print the message
64 | if (p < limit) {
65 | va_list backup_ap;
66 | va_copy(backup_ap, ap);
67 | p += vsnprintf(p, limit - p, format, backup_ap);
68 | va_end(backup_ap);
69 | }
70 |
71 | // Truncate to available space if necessary
72 | if (p >= limit) {
73 | if (iter == 0) {
74 | continue; // Try again with larger buffer
75 | } else {
76 | p = limit - 1;
77 | }
78 | }
79 |
80 | // Add newline if necessary
81 | if (p == base || p[-1] != '\n') {
82 | *p++ = '\n';
83 | }
84 |
85 | assert(p <= limit);
86 | fwrite(base, 1, p - base, file_);
87 | fflush(file_);
88 | if (base != buffer) {
89 | delete[] base;
90 | }
91 | break;
92 | }
93 | }
94 | };
95 |
96 | } // namespace leveldb
97 |
98 | #endif // STORAGE_LEVELDB_UTIL_POSIX_LOGGER_H_
99 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/random.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_
6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_
7 |
8 | #include
9 |
10 | namespace leveldb {
11 |
12 | // A very simple random number generator. Not especially good at
13 | // generating truly random bits, but good enough for our needs in this
14 | // package.
15 | class Random {
16 | private:
17 | uint32_t seed_;
18 | public:
19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) {
20 | // Avoid bad seeds.
21 | if (seed_ == 0 || seed_ == 2147483647L) {
22 | seed_ = 1;
23 | }
24 | }
25 | uint32_t Next() {
26 | static const uint32_t M = 2147483647L; // 2^31-1
27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0
28 | // We are computing
29 | // seed_ = (seed_ * A) % M, where M = 2^31-1
30 | //
31 | // seed_ must not be zero or M, or else all subsequent computed values
32 | // will be zero or M respectively. For all other values, seed_ will end
33 | // up cycling through every number in [1,M-1]
34 | uint64_t product = seed_ * A;
35 |
36 | // Compute (product % M) using the fact that ((x << 31) % M) == x.
37 | seed_ = static_cast((product >> 31) + (product & M));
38 | // The first reduction may overflow by 1 bit, so we may need to
39 | // repeat. mod == M is not possible; using > allows the faster
40 | // sign-bit-based test.
41 | if (seed_ > M) {
42 | seed_ -= M;
43 | }
44 | return seed_;
45 | }
46 | // Returns a uniformly distributed value in the range [0..n-1]
47 | // REQUIRES: n > 0
48 | uint32_t Uniform(int n) { return Next() % n; }
49 |
50 | // Randomly returns true ~"1/n" of the time, and false otherwise.
51 | // REQUIRES: n > 0
52 | bool OneIn(int n) { return (Next() % n) == 0; }
53 |
54 | // Skewed: pick "base" uniformly from range [0,max_log] and then
55 | // return "base" random bits. The effect is to pick a number in the
56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers.
57 | uint32_t Skewed(int max_log) {
58 | return Uniform(1 << Uniform(max_log + 1));
59 | }
60 | };
61 |
62 | } // namespace leveldb
63 |
64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_
65 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/status.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include
6 | #include "port/port.h"
7 | #include "hyperleveldb/status.h"
8 |
9 | namespace leveldb {
10 |
11 | const char* Status::CopyState(const char* state) {
12 | uint32_t size;
13 | memcpy(&size, state, sizeof(size));
14 | char* result = new char[size + 5];
15 | memcpy(result, state, size + 5);
16 | return result;
17 | }
18 |
19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) {
20 | assert(code != kOk);
21 | const uint32_t len1 = msg.size();
22 | const uint32_t len2 = msg2.size();
23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
24 | char* result = new char[size + 5];
25 | memcpy(result, &size, sizeof(size));
26 | result[4] = static_cast(code);
27 | memcpy(result + 5, msg.data(), len1);
28 | if (len2) {
29 | result[5 + len1] = ':';
30 | result[6 + len1] = ' ';
31 | memcpy(result + 7 + len1, msg2.data(), len2);
32 | }
33 | state_ = result;
34 | }
35 |
36 | std::string Status::ToString() const {
37 | if (state_ == NULL) {
38 | return "OK";
39 | } else {
40 | char tmp[30];
41 | const char* type;
42 | switch (code()) {
43 | case kOk:
44 | type = "OK";
45 | break;
46 | case kNotFound:
47 | type = "NotFound: ";
48 | break;
49 | case kCorruption:
50 | type = "Corruption: ";
51 | break;
52 | case kNotSupported:
53 | type = "Not implemented: ";
54 | break;
55 | case kInvalidArgument:
56 | type = "Invalid argument: ";
57 | break;
58 | case kIOError:
59 | type = "IO error: ";
60 | break;
61 | default:
62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
63 | static_cast(code()));
64 | type = tmp;
65 | break;
66 | }
67 | std::string result(type);
68 | uint32_t length;
69 | memcpy(&length, state_, sizeof(length));
70 | result.append(state_ + 5, length);
71 | return result;
72 | }
73 | }
74 |
75 | } // namespace leveldb
76 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/testharness.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/testharness.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | namespace leveldb {
13 | namespace test {
14 |
15 | namespace {
16 | struct Test {
17 | const char* base;
18 | const char* name;
19 | void (*func)();
20 | };
21 | std::vector* tests;
22 | }
23 |
24 | bool RegisterTest(const char* base, const char* name, void (*func)()) {
25 | if (tests == NULL) {
26 | tests = new std::vector;
27 | }
28 | Test t;
29 | t.base = base;
30 | t.name = name;
31 | t.func = func;
32 | tests->push_back(t);
33 | return true;
34 | }
35 |
36 | int RunAllTests() {
37 | const char* matcher = getenv("LEVELDB_TESTS");
38 |
39 | int num = 0;
40 | if (tests != NULL) {
41 | for (int i = 0; i < tests->size(); i++) {
42 | const Test& t = (*tests)[i];
43 | if (matcher != NULL) {
44 | std::string name = t.base;
45 | name.push_back('.');
46 | name.append(t.name);
47 | if (strstr(name.c_str(), matcher) == NULL) {
48 | continue;
49 | }
50 | }
51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name);
52 | (*t.func)();
53 | ++num;
54 | }
55 | }
56 | fprintf(stderr, "==== PASSED %d tests\n", num);
57 | return 0;
58 | }
59 |
60 | std::string TmpDir() {
61 | std::string dir;
62 | Status s = Env::Default()->GetTestDirectory(&dir);
63 | ASSERT_TRUE(s.ok()) << s.ToString();
64 | return dir;
65 | }
66 |
67 | int RandomSeed() {
68 | const char* env = getenv("TEST_RANDOM_SEED");
69 | int result = (env != NULL ? atoi(env) : 301);
70 | if (result <= 0) {
71 | result = 301;
72 | }
73 | return result;
74 | }
75 |
76 | } // namespace test
77 | } // namespace leveldb
78 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/testutil.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "util/testutil.h"
6 |
7 | #include "util/random.h"
8 |
9 | namespace leveldb {
10 | namespace test {
11 |
12 | Slice RandomString(Random* rnd, int len, std::string* dst) {
13 | dst->resize(len);
14 | for (int i = 0; i < len; i++) {
15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~'
16 | }
17 | return Slice(*dst);
18 | }
19 |
20 | std::string RandomKey(Random* rnd, int len) {
21 | // Make sure to generate a wide variety of characters so we
22 | // test the boundary conditions for short-key optimizations.
23 | static const char kTestChars[] = {
24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff'
25 | };
26 | std::string result;
27 | for (int i = 0; i < len; i++) {
28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))];
29 | }
30 | return result;
31 | }
32 |
33 |
34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction,
35 | int len, std::string* dst) {
36 | int raw = static_cast(len * compressed_fraction);
37 | if (raw < 1) raw = 1;
38 | std::string raw_data;
39 | RandomString(rnd, raw, &raw_data);
40 |
41 | // Duplicate the random data until we have filled "len" bytes
42 | dst->clear();
43 | while (dst->size() < len) {
44 | dst->append(raw_data);
45 | }
46 | dst->resize(len);
47 | return Slice(*dst);
48 | }
49 |
50 | } // namespace test
51 | } // namespace leveldb
52 |
--------------------------------------------------------------------------------
/deps/leveldb/leveldb-hyper-1.0.2/util/testutil.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_
6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_
7 |
8 | #include "hyperleveldb/env.h"
9 | #include "hyperleveldb/slice.h"
10 | #include "util/random.h"
11 |
12 | namespace leveldb {
13 | namespace test {
14 |
15 | // Store in *dst a random string of length "len" and return a Slice that
16 | // references the generated data.
17 | extern Slice RandomString(Random* rnd, int len, std::string* dst);
18 |
19 | // Return a random key with the specified length that may contain interesting
20 | // characters (e.g. \x00, \xff, etc.).
21 | extern std::string RandomKey(Random* rnd, int len);
22 |
23 | // Store in *dst a string of length "len" that will compress to
24 | // "N*compressed_fraction" bytes and return a Slice that references
25 | // the generated data.
26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction,
27 | int len, std::string* dst);
28 |
29 | // A wrapper that allows injection of errors.
30 | class ErrorEnv : public EnvWrapper {
31 | public:
32 | bool writable_file_error_;
33 | int num_writable_file_errors_;
34 |
35 | ErrorEnv() : EnvWrapper(Env::Default()),
36 | writable_file_error_(false),
37 | num_writable_file_errors_(0) { }
38 |
39 | virtual Status NewWritableFile(const std::string& fname,
40 | WritableFile** result) {
41 | if (writable_file_error_) {
42 | ++num_writable_file_errors_;
43 | *result = NULL;
44 | return Status::IOError(fname, "fake error");
45 | }
46 | return target()->NewWritableFile(fname, result);
47 | }
48 | };
49 |
50 | } // namespace test
51 | } // namespace leveldb
52 |
53 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_
54 |
--------------------------------------------------------------------------------
/deps/leveldb/port-libuv/atomic_pointer_win.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // credit: https://groups.google.com/forum/#!msg/leveldb/VuECZMnsob4/F6pGPGaK-XwJ
5 |
6 | namespace leveldb {
7 | namespace port {
8 |
9 | class AtomicPointer {
10 | private:
11 | void* rep_;
12 |
13 | public:
14 | AtomicPointer () {}
15 | explicit AtomicPointer(void* v) {
16 | InterlockedExchangePointer(&rep_, v);
17 | }
18 |
19 | // Read and return the stored pointer with the guarantee that no
20 | // later memory access (read or write) by this thread can be
21 | // reordered ahead of this read.
22 | inline void* Acquire_Load() const {
23 | void* r;
24 | InterlockedExchangePointer(&r, rep_ );
25 | return r;
26 | }
27 |
28 | // Set v as the stored pointer with the guarantee that no earlier
29 | // memory access (read or write) by this thread can be reordered
30 | // after this store.
31 | inline void Release_Store(void* v) {
32 | InterlockedExchangePointer(&rep_, v);
33 | }
34 |
35 | // Read the stored pointer with no ordering guarantees.
36 | inline void* NoBarrier_Load() const {
37 | void* r = reinterpret_cast(rep_);
38 | return r;
39 | }
40 |
41 | // Set va as the stored pointer with no ordering guarantees.
42 | inline void NoBarrier_Store(void* v) {
43 | rep_ = reinterpret_cast(v);
44 | }
45 | };
46 |
47 | } // namespace port
48 | } // namespace leveldb
49 |
--------------------------------------------------------------------------------
/deps/leveldb/port-libuv/port_uv.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "port_uv.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include "util/logging.h"
11 |
12 | namespace leveldb {
13 | namespace port {
14 |
15 | Mutex::Mutex() { uv_mutex_init(&mu_); }
16 |
17 | Mutex::~Mutex() { uv_mutex_destroy(&mu_); }
18 |
19 | void Mutex::Lock() { uv_mutex_lock(&mu_); }
20 |
21 | void Mutex::Unlock() { uv_mutex_unlock(&mu_); }
22 |
23 | CondVar::CondVar(Mutex* mu) : mu_(mu) { uv_cond_init(&cv_); }
24 |
25 | CondVar::~CondVar() { uv_cond_destroy(&cv_); }
26 |
27 | void CondVar::Wait() { uv_cond_wait(&cv_, &mu_->mu_); }
28 |
29 | void CondVar::Signal() { uv_cond_signal(&cv_); }
30 |
31 | void CondVar::SignalAll() { uv_cond_broadcast(&cv_); }
32 |
33 | void InitOnce(OnceType* once, void (*initializer)()) { uv_once(once, initializer); }
34 |
35 | } // namespace port
36 | } // namespace leveldb
37 |
--------------------------------------------------------------------------------
/deps/leveldb/port-libuv/uv_condvar.h:
--------------------------------------------------------------------------------
1 | // uv_cond_* backport
2 | // Lifted from the Node 0.9 version of libuv for Node 0.8 compatibility
3 | // https://github.com/joyent/libuv/
4 |
5 | // libuv copyright notice:
6 |
7 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
8 | *
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy
10 | * of this software and associated documentation files (the "Software"), to
11 | * deal in the Software without restriction, including without limitation the
12 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 | * sell copies of the Software, and to permit persons to whom the Software is
14 | * furnished to do so, subject to the following conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be included in
17 | * all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 | * IN THE SOFTWARE.
26 | */
27 |
28 | #ifndef LEVELDB_PORT_LIBUV_CONVAR_H_
29 | #define LEVELDB_PORT_LIBUV_CONVAR_H_
30 |
31 | #include
32 |
33 | #ifdef LDB_UV_POSIX
34 | typedef pthread_cond_t ldb_uv_cond_t;
35 | #endif
36 |
37 |
38 | UV_EXTERN int ldb_uv_cond_init(ldb_uv_cond_t* cond);
39 | UV_EXTERN void ldb_uv_cond_destroy(ldb_uv_cond_t* cond);
40 | UV_EXTERN void ldb_uv_cond_signal(ldb_uv_cond_t* cond);
41 | UV_EXTERN void ldb_uv_cond_broadcast(ldb_uv_cond_t* cond);
42 | UV_EXTERN void ldb_uv_cond_wait(ldb_uv_cond_t* cond, uv_mutex_t* mutex);
43 | UV_EXTERN int ldb_uv_cond_timedwait(ldb_uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout);
44 |
45 | #endif // LEVELDB_PORT_LIBUV_CONVAR_H_
46 |
--------------------------------------------------------------------------------
/deps/leveldb/port-libuv/win_logger.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | #include "win_logger.h"
6 |
7 | #include
8 |
9 | namespace leveldb {
10 |
11 | void WinLogger::Logv(const char* format, va_list ap) {
12 | const uint64_t thread_id = static_cast(::GetCurrentThreadId());
13 |
14 | // We try twice: the first time with a fixed-size stack allocated buffer,
15 | // and the second time with a much larger dynamically allocated buffer.
16 | char buffer[500];
17 |
18 | for (int iter = 0; iter < 2; iter++) {
19 | char* base;
20 | int bufsize;
21 | if (iter == 0) {
22 | bufsize = sizeof(buffer);
23 | base = buffer;
24 | } else {
25 | bufsize = 30000;
26 | base = new char[bufsize];
27 | }
28 |
29 | char* p = base;
30 | char* limit = base + bufsize;
31 |
32 | SYSTEMTIME st;
33 |
34 | // GetSystemTime returns UTC time, we want local time!
35 | ::GetLocalTime(&st);
36 |
37 | p += _snprintf_s(p, limit - p, _TRUNCATE,
38 | "%04d/%02d/%02d-%02d:%02d:%02d.%03d %llx ",
39 | st.wYear,
40 | st.wMonth,
41 | st.wDay,
42 | st.wHour,
43 | st.wMinute,
44 | st.wSecond,
45 | st.wMilliseconds,
46 | static_cast(thread_id));
47 |
48 | // Print the message
49 | if (p < limit) {
50 | va_list backup_ap = ap;
51 | p += vsnprintf(p, limit - p, format, backup_ap);
52 | va_end(backup_ap);
53 | }
54 |
55 | // Truncate to available space if necessary
56 | if (p >= limit) {
57 | if (iter == 0) {
58 | continue; // Try again with larger buffer
59 | } else {
60 | p = limit - 1;
61 | }
62 | }
63 |
64 | // Add newline if necessary
65 | if (p == base || p[-1] != '\n') {
66 | *p++ = '\n';
67 | }
68 |
69 | assert(p <= limit);
70 | fwrite(base, 1, p - base, file_);
71 | fflush(file_);
72 | if (base != buffer) {
73 | delete[] base;
74 | }
75 | break;
76 | }
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/deps/leveldb/port-libuv/win_logger.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 |
5 | // Logger implementation for Windows
6 |
7 | #ifndef STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_
8 | #define STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_
9 |
10 | #include
11 | #include "leveldb/env.h"
12 |
13 | namespace leveldb {
14 |
15 | class WinLogger : public Logger {
16 | private:
17 | FILE* file_;
18 | public:
19 | explicit WinLogger(FILE* f) : file_(f) { assert(file_); }
20 | virtual ~WinLogger() {
21 | fclose(file_);
22 | }
23 | virtual void Logv(const char* format, va_list ap);
24 |
25 | };
26 |
27 | }
28 | #endif // STORAGE_LEVELDB_UTIL_WIN_LOGGER_H_
29 |
--------------------------------------------------------------------------------
/deps/snappy/freebsd/snappy-stubs-public.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | // Author: sesse@google.com (Steinar H. Gunderson)
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Various type stubs for the open-source version of Snappy.
31 | //
32 | // This file cannot include config.h, as it is included from snappy.h,
33 | // which is a public header. Instead, snappy-stubs-public.h is generated by
34 | // from snappy-stubs-public.h.in at configure time.
35 |
36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38 |
39 | #if 1
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #define SNAPPY_MAJOR 1
48 | #define SNAPPY_MINOR 0
49 | #define SNAPPY_PATCHLEVEL 5
50 | #define SNAPPY_VERSION \
51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
52 |
53 | #include
54 |
55 | namespace snappy {
56 |
57 | #if 1
58 | typedef int8_t int8;
59 | typedef uint8_t uint8;
60 | typedef int16_t int16;
61 | typedef uint16_t uint16;
62 | typedef int32_t int32;
63 | typedef uint32_t uint32;
64 | typedef int64_t int64;
65 | typedef uint64_t uint64;
66 | #else
67 | typedef signed char int8;
68 | typedef unsigned char uint8;
69 | typedef short int16;
70 | typedef unsigned short uint16;
71 | typedef int int32;
72 | typedef unsigned int uint32;
73 | typedef long long int64;
74 | typedef unsigned long long uint64;
75 | #endif
76 |
77 | typedef std::string string;
78 |
79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
80 | TypeName(const TypeName&); \
81 | void operator=(const TypeName&)
82 |
83 | } // namespace snappy
84 |
85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
86 |
--------------------------------------------------------------------------------
/deps/snappy/linux/snappy-stubs-public.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | // Author: sesse@google.com (Steinar H. Gunderson)
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Various type stubs for the open-source version of Snappy.
31 | //
32 | // This file cannot include config.h, as it is included from snappy.h,
33 | // which is a public header. Instead, snappy-stubs-public.h is generated by
34 | // from snappy-stubs-public.h.in at configure time.
35 |
36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38 |
39 | #if 1
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #define SNAPPY_MAJOR 1
48 | #define SNAPPY_MINOR 0
49 | #define SNAPPY_PATCHLEVEL 5
50 | #define SNAPPY_VERSION \
51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
52 |
53 | #include
54 |
55 | namespace snappy {
56 |
57 | #if 1
58 | typedef int8_t int8;
59 | typedef uint8_t uint8;
60 | typedef int16_t int16;
61 | typedef uint16_t uint16;
62 | typedef int32_t int32;
63 | typedef uint32_t uint32;
64 | typedef int64_t int64;
65 | typedef uint64_t uint64;
66 | #else
67 | typedef signed char int8;
68 | typedef unsigned char uint8;
69 | typedef short int16;
70 | typedef unsigned short uint16;
71 | typedef int int32;
72 | typedef unsigned int uint32;
73 | typedef long long int64;
74 | typedef unsigned long long uint64;
75 | #endif
76 |
77 | typedef std::string string;
78 |
79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
80 | TypeName(const TypeName&); \
81 | void operator=(const TypeName&)
82 |
83 | } // namespace snappy
84 |
85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
86 |
--------------------------------------------------------------------------------
/deps/snappy/mac/snappy-stubs-public.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | // Author: sesse@google.com (Steinar H. Gunderson)
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Various type stubs for the open-source version of Snappy.
31 | //
32 | // This file cannot include config.h, as it is included from snappy.h,
33 | // which is a public header. Instead, snappy-stubs-public.h is generated by
34 | // from snappy-stubs-public.h.in at configure time.
35 |
36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38 |
39 | #if 1
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #define SNAPPY_MAJOR 1
48 | #define SNAPPY_MINOR 0
49 | #define SNAPPY_PATCHLEVEL 5
50 | #define SNAPPY_VERSION \
51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
52 |
53 | #include
54 |
55 | namespace snappy {
56 |
57 | #if 1
58 | typedef int8_t int8;
59 | typedef uint8_t uint8;
60 | typedef int16_t int16;
61 | typedef uint16_t uint16;
62 | typedef int32_t int32;
63 | typedef uint32_t uint32;
64 | typedef int64_t int64;
65 | typedef uint64_t uint64;
66 | #else
67 | typedef signed char int8;
68 | typedef unsigned char uint8;
69 | typedef short int16;
70 | typedef unsigned short uint16;
71 | typedef int int32;
72 | typedef unsigned int uint32;
73 | typedef long long int64;
74 | typedef unsigned long long uint64;
75 | #endif
76 |
77 | typedef std::string string;
78 |
79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
80 | TypeName(const TypeName&); \
81 | void operator=(const TypeName&)
82 |
83 | } // namespace snappy
84 |
85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
86 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/AUTHORS:
--------------------------------------------------------------------------------
1 | opensource@google.com
2 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/COPYING:
--------------------------------------------------------------------------------
1 | Copyright 2011, Google Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/Makefile.am:
--------------------------------------------------------------------------------
1 | ACLOCAL_AMFLAGS = -I m4
2 |
3 | # Library.
4 | lib_LTLIBRARIES = libsnappy.la
5 | libsnappy_la_SOURCES = snappy.cc snappy-sinksource.cc snappy-stubs-internal.cc snappy-c.cc
6 | libsnappy_la_LDFLAGS = -version-info $(SNAPPY_LTVERSION)
7 |
8 | include_HEADERS = snappy.h snappy-sinksource.h snappy-stubs-public.h snappy-c.h
9 | noinst_HEADERS = snappy-internal.h snappy-stubs-internal.h snappy-test.h
10 |
11 | # Unit tests and benchmarks.
12 | snappy_unittest_CPPFLAGS = $(gflags_CFLAGS) $(GTEST_CPPFLAGS)
13 | snappy_unittest_SOURCES = snappy_unittest.cc snappy-test.cc
14 | snappy_unittest_LDFLAGS = $(GTEST_LDFLAGS)
15 | snappy_unittest_LDADD = libsnappy.la $(UNITTEST_LIBS) $(gflags_LIBS) $(GTEST_LIBS)
16 | TESTS = snappy_unittest
17 | noinst_PROGRAMS = $(TESTS)
18 |
19 | EXTRA_DIST = autogen.sh testdata/alice29.txt testdata/asyoulik.txt testdata/baddata1.snappy testdata/baddata2.snappy testdata/baddata3.snappy testdata/cp.html testdata/fields.c testdata/geo.protodata testdata/grammar.lsp testdata/house.jpg testdata/html testdata/html_x_4 testdata/kennedy.xls testdata/kppkn.gtb testdata/lcet10.txt testdata/mapreduce-osdi-1.pdf testdata/plrabn12.txt testdata/ptt5 testdata/sum testdata/urls.10K testdata/xargs.1
20 | dist_doc_DATA = ChangeLog COPYING INSTALL NEWS README format_description.txt framing_format.txt
21 |
22 | libtool: $(LIBTOOL_DEPS)
23 | $(SHELL) ./config.status --recheck
24 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/autogen.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh -e
2 | rm -rf autom4te.cache
3 | aclocal -I m4
4 | autoheader
5 | libtoolize --copy
6 | automake --add-missing --copy
7 | autoconf
8 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/snappy-sinksource.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are
5 | // met:
6 | //
7 | // * Redistributions of source code must retain the above copyright
8 | // notice, this list of conditions and the following disclaimer.
9 | // * Redistributions in binary form must reproduce the above
10 | // copyright notice, this list of conditions and the following disclaimer
11 | // in the documentation and/or other materials provided with the
12 | // distribution.
13 | // * Neither the name of Google Inc. nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 |
31 | #include "snappy-sinksource.h"
32 |
33 | namespace snappy {
34 |
35 | Source::~Source() { }
36 |
37 | Sink::~Sink() { }
38 |
39 | char* Sink::GetAppendBuffer(size_t length, char* scratch) {
40 | return scratch;
41 | }
42 |
43 | ByteArraySource::~ByteArraySource() { }
44 |
45 | size_t ByteArraySource::Available() const { return left_; }
46 |
47 | const char* ByteArraySource::Peek(size_t* len) {
48 | *len = left_;
49 | return ptr_;
50 | }
51 |
52 | void ByteArraySource::Skip(size_t n) {
53 | left_ -= n;
54 | ptr_ += n;
55 | }
56 |
57 | UncheckedByteArraySink::~UncheckedByteArraySink() { }
58 |
59 | void UncheckedByteArraySink::Append(const char* data, size_t n) {
60 | // Do no copying if the caller filled in the result of GetAppendBuffer()
61 | if (data != dest_) {
62 | memcpy(dest_, data, n);
63 | }
64 | dest_ += n;
65 | }
66 |
67 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) {
68 | return dest_;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/snappy-stubs-internal.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are
5 | // met:
6 | //
7 | // * Redistributions of source code must retain the above copyright
8 | // notice, this list of conditions and the following disclaimer.
9 | // * Redistributions in binary form must reproduce the above
10 | // copyright notice, this list of conditions and the following disclaimer
11 | // in the documentation and/or other materials provided with the
12 | // distribution.
13 | // * Neither the name of Google Inc. nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 | #include
31 |
32 | #include "snappy-stubs-internal.h"
33 |
34 | namespace snappy {
35 |
36 | void Varint::Append32(string* s, uint32 value) {
37 | char buf[Varint::kMax32];
38 | const char* p = Varint::Encode32(buf, value);
39 | s->append(buf, p - buf);
40 | }
41 |
42 | } // namespace snappy
43 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/baddata1.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata1.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/baddata2.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata2.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/baddata3.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/baddata3.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/cp.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/cp.html
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/geo.protodata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/geo.protodata
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/house.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/house.jpg
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/kennedy.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/kennedy.xls
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/mapreduce-osdi-1.pdf
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/ptt5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/ptt5
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.1/testdata/sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/leveldown-hyper/7a4a04dbbc413cf33c17c1e80a30985779e21262/deps/snappy/snappy-1.1.1/testdata/sum
--------------------------------------------------------------------------------
/deps/snappy/snappy.gyp:
--------------------------------------------------------------------------------
1 | {'targets': [{
2 | 'variables': {
3 | 'conditions': [
4 | ['OS=="linux"', {'os_include': 'linux'}]
5 | , ['OS=="mac"', {'os_include': 'mac'}]
6 | , ['OS=="solaris"', {'os_include': 'solaris'}]
7 | , ['OS=="win"', {'os_include': 'win32'}]
8 | , ['OS=="freebsd"', {'os_include': 'freebsd'}]
9 | ]
10 | }
11 | , 'target_name': 'snappy'
12 | , 'type': 'static_library'
13 | # Overcomes an issue with the linker and thin .a files on SmartOS
14 | , 'standalone_static_library': 1
15 | , 'include_dirs': [
16 | '<(os_include)'
17 | , 'snappy-1.1.1'
18 | ]
19 | , 'direct_dependent_settings': {
20 | 'include_dirs': [
21 | 'snappy-1.1.1'
22 | ]
23 | }
24 | , 'defines': [
25 | 'HAVE_CONFIG_H=1'
26 | ]
27 | , 'conditions': [
28 | ['OS == "win"', {
29 | 'defines': [
30 | '_HAS_EXCEPTIONS=0'
31 | ]
32 | , 'msvs_settings': {
33 | 'VCCLCompilerTool': {
34 | 'RuntimeTypeInfo': 'false'
35 | , 'EnableFunctionLevelLinking': 'true'
36 | , 'ExceptionHandling': '2'
37 | , 'DisableSpecificWarnings': [ '4355', '4530' ,'4267', '4244', '4506', '4018' ]
38 | }
39 | }
40 | }]
41 | , ['OS == "linux"', {
42 | 'cflags': [
43 | '-Wno-sign-compare'
44 | , '-Wno-unused-function'
45 | ]
46 | , 'cflags!': [ '-fno-tree-vrp' ]
47 | }]
48 | , ['OS == "freebsd"', {
49 | 'cflags': [
50 | '-Wno-sign-compare'
51 | , '-Wno-unused-function'
52 | ]
53 | }]
54 | , ['OS == "solaris"', {
55 | 'cflags': [
56 | '-Wno-sign-compare'
57 | , '-Wno-unused-function'
58 | ]
59 | }]
60 | , ['OS == "mac"', {
61 | 'xcode_settings': {
62 | 'WARNING_CFLAGS': [
63 | '-Wno-sign-compare'
64 | , '-Wno-unused-function'
65 | ]
66 | }
67 | }]
68 | ]
69 | , 'sources': [
70 | 'snappy-1.1.1/snappy-internal.h'
71 | , 'snappy-1.1.1/snappy-sinksource.cc'
72 | , 'snappy-1.1.1/snappy-sinksource.h'
73 | , 'snappy-1.1.1/snappy-stubs-internal.cc'
74 | , 'snappy-1.1.1/snappy-stubs-internal.h'
75 | , 'snappy-1.1.1/snappy.cc'
76 | , 'snappy-1.1.1/snappy.h'
77 | ]
78 | }]}
79 |
--------------------------------------------------------------------------------
/deps/snappy/solaris/snappy-stubs-public.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | // Author: sesse@google.com (Steinar H. Gunderson)
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Various type stubs for the open-source version of Snappy.
31 | //
32 | // This file cannot include config.h, as it is included from snappy.h,
33 | // which is a public header. Instead, snappy-stubs-public.h is generated by
34 | // from snappy-stubs-public.h.in at configure time.
35 |
36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38 |
39 | #if 1
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #define SNAPPY_MAJOR 1
48 | #define SNAPPY_MINOR 0
49 | #define SNAPPY_PATCHLEVEL 5
50 | #define SNAPPY_VERSION \
51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
52 |
53 | #include
54 |
55 | namespace snappy {
56 |
57 | #if 1
58 | typedef int8_t int8;
59 | typedef uint8_t uint8;
60 | typedef int16_t int16;
61 | typedef uint16_t uint16;
62 | typedef int32_t int32;
63 | typedef uint32_t uint32;
64 | typedef int64_t int64;
65 | typedef uint64_t uint64;
66 | #else
67 | typedef signed char int8;
68 | typedef unsigned char uint8;
69 | typedef short int16;
70 | typedef unsigned short uint16;
71 | typedef int int32;
72 | typedef unsigned int uint32;
73 | typedef long long int64;
74 | typedef unsigned long long uint64;
75 | #endif
76 |
77 | typedef std::string string;
78 |
79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
80 | TypeName(const TypeName&); \
81 | void operator=(const TypeName&)
82 |
83 | } // namespace snappy
84 |
85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
86 |
--------------------------------------------------------------------------------
/deps/snappy/win32/config.h:
--------------------------------------------------------------------------------
1 | #include
2 | typedef SSIZE_T ssize_t;
3 |
4 | /* Define to 1 if you have the header file. */
5 | #define HAVE_WINDOWS_H 1
6 |
7 | /* Name of package */
8 | #define PACKAGE "snappy"
9 |
10 | /* Define to the address where bug reports for this package should be sent. */
11 | #define PACKAGE_BUGREPORT ""
12 |
13 | /* Define to the full name of this package. */
14 | #define PACKAGE_NAME "snappy"
15 |
16 | /* Define to the full name and version of this package. */
17 | #define PACKAGE_STRING "snappy 1.1.1"
18 |
19 | /* Define to the one symbol short name of this package. */
20 | #define PACKAGE_TARNAME "snappy"
21 |
22 | /* Define to the version of this package. */
23 | #define PACKAGE_VERSION "1.1.1"
24 |
25 | /* Define to 1 if you have the ANSI C header files. */
26 | #define STDC_HEADERS 1
27 |
28 | /* Version number of package */
29 | #define VERSION "1.1.1"
30 |
--------------------------------------------------------------------------------
/deps/snappy/win32/snappy-stubs-public.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | // Author: sesse@google.com (Steinar H. Gunderson)
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Various type stubs for the open-source version of Snappy.
31 | //
32 | // This file cannot include config.h, as it is included from snappy.h,
33 | // which is a public header. Instead, snappy-stubs-public.h is generated by
34 | // from snappy-stubs-public.h.in at configure time.
35 |
36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38 |
39 | #if 0
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #define SNAPPY_MAJOR 1
48 | #define SNAPPY_MINOR 1
49 | #define SNAPPY_PATCHLEVEL 1
50 | #define SNAPPY_VERSION \
51 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
52 |
53 | #include
54 |
55 | namespace snappy {
56 |
57 | #if 0
58 | typedef int8_t int8;
59 | typedef uint8_t uint8;
60 | typedef int16_t int16;
61 | typedef uint16_t uint16;
62 | typedef int32_t int32;
63 | typedef uint32_t uint32;
64 | typedef int64_t int64;
65 | typedef uint64_t uint64;
66 | #else
67 | typedef signed char int8;
68 | typedef unsigned char uint8;
69 | typedef short int16;
70 | typedef unsigned short uint16;
71 | typedef int int32;
72 | typedef unsigned int uint32;
73 | typedef long long int64;
74 | typedef unsigned long long uint64;
75 | #endif
76 |
77 | typedef std::string string;
78 |
79 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
80 | TypeName(const TypeName&); \
81 | void operator=(const TypeName&)
82 |
83 | } // namespace snappy
84 |
85 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
86 |
--------------------------------------------------------------------------------
/iterator.js:
--------------------------------------------------------------------------------
1 | const util = require('util')
2 | const AbstractIterator = require('abstract-leveldown').AbstractIterator
3 |
4 | function Iterator (db, options) {
5 | AbstractIterator.call(this, db)
6 |
7 | this.binding = db.binding.iterator(options)
8 | this.cache = null
9 | this.finished = false
10 | this.fastFuture = require('fast-future')()
11 | }
12 |
13 | util.inherits(Iterator, AbstractIterator)
14 |
15 | Iterator.prototype.seek = function (target) {
16 | if (this._ended) {
17 | throw new Error('cannot call seek() after end()')
18 | }
19 | if (this._nexting) {
20 | throw new Error('cannot call seek() before next() has completed')
21 | }
22 | if (typeof target !== 'string' && !Buffer.isBuffer(target)) {
23 | throw new Error('seek() requires a string or buffer key')
24 | }
25 | if (target.length === 0) {
26 | throw new Error('cannot seek() to an empty key')
27 | }
28 |
29 | this.cache = null
30 | this.binding.seek(target)
31 | this.finished = false
32 | }
33 |
34 | Iterator.prototype._next = function (callback) {
35 | var that = this
36 | var key
37 | var value
38 |
39 | if (this.cache && this.cache.length) {
40 | key = this.cache.pop()
41 | value = this.cache.pop()
42 |
43 | this.fastFuture(function () {
44 | callback(null, key, value)
45 | })
46 | } else if (this.finished) {
47 | this.fastFuture(function () {
48 | callback()
49 | })
50 | } else {
51 | this.binding.next(function (err, array, finished) {
52 | if (err) return callback(err)
53 |
54 | that.cache = array
55 | that.finished = finished
56 | that._next(callback)
57 | })
58 | }
59 |
60 | return this
61 | }
62 |
63 | Iterator.prototype._end = function (callback) {
64 | delete this.cache
65 | this.binding.end(callback)
66 | }
67 |
68 | module.exports = Iterator
69 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "leveldown-hyper",
3 | "version": "2.0.0",
4 | "description": "A Node.js LevelDB binding, primary backend for LevelUP (HyperDex fork)",
5 | "license": "MIT",
6 | "main": "leveldown-hyper.js",
7 | "scripts": {
8 | "install": "prebuild-install || node-gyp rebuild",
9 | "test": "standard && hallmark && (nyc -s tape test/*-test.js | faucet) && nyc report && prebuild-ci",
10 | "coverage": "nyc report --reporter=text-lcov | coveralls",
11 | "rebuild": "node-gyp rebuild",
12 | "prebuild": "prebuild --all --verbose --strip",
13 | "hallmark": "hallmark --fix",
14 | "dependency-check": "dependency-check . test/*.js bench/*.js",
15 | "prepublishOnly": "npm run dependency-check"
16 | },
17 | "dependencies": {
18 | "abstract-leveldown": "~5.0.0",
19 | "bindings": "~1.5.0",
20 | "fast-future": "~1.0.0",
21 | "nan": "^2.6.2",
22 | "prebuild-install": "^5.0.0"
23 | },
24 | "devDependencies": {
25 | "coveralls": "^3.0.2",
26 | "dependency-check": "^3.3.0",
27 | "du": "^1.0.0",
28 | "faucet": "^0.0.1",
29 | "hallmark": "^2.0.0",
30 | "iota-array": "^1.0.0",
31 | "level-community": "^3.0.0",
32 | "lexicographic-integer": "^1.1.0",
33 | "mkfiletree": "^2.0.0",
34 | "monotonic-timestamp": "~0.0.8",
35 | "node-uuid": "^1.4.3",
36 | "nyc": "^14.0.0",
37 | "optimist": "~0.6.1",
38 | "prebuild": "^9.0.0",
39 | "prebuild-ci": "^3.0.0",
40 | "readfiletree": "^1.0.0",
41 | "rimraf": "^3.0.0",
42 | "slump": "^3.0.0",
43 | "standard": "^14.0.0",
44 | "tape": "^4.9.0"
45 | },
46 | "hallmark": {
47 | "community": "level-community"
48 | },
49 | "gypfile": true,
50 | "repository": {
51 | "type": "git",
52 | "url": "https://github.com/Level/leveldown-hyper.git"
53 | },
54 | "homepage": "https://github.com/Level/leveldown-hyper",
55 | "keywords": [
56 | "leveldb",
57 | "level"
58 | ],
59 | "engines": {
60 | "node": ">=6"
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/async.h:
--------------------------------------------------------------------------------
1 | #ifndef LD_ASYNC_H
2 | #define LD_ASYNC_H
3 |
4 | #include
5 | #include
6 | #include "database.h"
7 |
8 | namespace leveldown {
9 |
10 | class Database;
11 |
12 | /* abstract */ class AsyncWorker : public Nan::AsyncWorker {
13 | public:
14 | AsyncWorker (
15 | leveldown::Database* database
16 | , Nan::Callback *callback
17 | , const char *resource_name
18 | ) : Nan::AsyncWorker(callback, resource_name), database(database) { }
19 |
20 | protected:
21 | void SetStatus(leveldb::Status status) {
22 | this->status = status;
23 | if (!status.ok())
24 | SetErrorMessage(status.ToString().c_str());
25 | }
26 | Database* database;
27 | private:
28 | leveldb::Status status;
29 | };
30 |
31 | } // namespace leveldown
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/src/batch.h:
--------------------------------------------------------------------------------
1 | #ifndef LD_BATCH_H
2 | #define LD_BATCH_H
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "database.h"
10 |
11 | namespace leveldown {
12 |
13 | class Batch : public Nan::ObjectWrap {
14 | public:
15 | static void Init();
16 | static v8::Local NewInstance (
17 | v8::Local database
18 | , v8::Local optionsObj
19 | );
20 |
21 | Batch (leveldown::Database* database, bool sync);
22 | ~Batch ();
23 | leveldb::Status Write ();
24 |
25 | private:
26 | leveldown::Database* database;
27 | leveldb::WriteOptions* options;
28 | leveldb::WriteBatch* batch;
29 | bool hasData; // keep track of whether we're writing data or not
30 |
31 | static NAN_METHOD(New);
32 | static NAN_METHOD(Put);
33 | static NAN_METHOD(Del);
34 | static NAN_METHOD(Clear);
35 | static NAN_METHOD(Write);
36 | };
37 |
38 | } // namespace leveldown
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/batch_async.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "batch.h"
3 | #include "batch_async.h"
4 |
5 | namespace leveldown {
6 |
7 | /** NEXT WORKER **/
8 |
9 | BatchWriteWorker::BatchWriteWorker (
10 | Batch* batch
11 | , Nan::Callback *callback
12 | ) : AsyncWorker(NULL, callback, "leveldown-hyper:batch.write")
13 | , batch(batch)
14 | {};
15 |
16 | BatchWriteWorker::~BatchWriteWorker () {}
17 |
18 | void BatchWriteWorker::Execute () {
19 | SetStatus(batch->Write());
20 | }
21 |
22 | } // namespace leveldown
23 |
--------------------------------------------------------------------------------
/src/batch_async.h:
--------------------------------------------------------------------------------
1 | #ifndef LD_BATCH_ASYNC_H
2 | #define LD_BATCH_ASYNC_H
3 |
4 | #include
5 | #include
6 |
7 | #include "async.h"
8 | #include "batch.h"
9 | #include "database.h"
10 |
11 | namespace leveldown {
12 |
13 | class BatchWriteWorker : public AsyncWorker {
14 | public:
15 | BatchWriteWorker (
16 | Batch* batch
17 | , Nan::Callback *callback
18 | );
19 |
20 | virtual ~BatchWriteWorker ();
21 | virtual void Execute ();
22 |
23 | private:
24 | Batch* batch;
25 | };
26 |
27 | } // namespace leveldown
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/common.h:
--------------------------------------------------------------------------------
1 | #ifndef LD_COMMON_H
2 | #define LD_COMMON_H
3 |
4 | #include
5 |
6 | namespace leveldown {
7 |
8 | NAN_INLINE bool BooleanOptionValue(v8::Local options,
9 | const char* _key,
10 | bool def = false) {
11 | Nan::HandleScope scope;
12 | v8::Local key = Nan::New(_key).ToLocalChecked();
13 | return !options.IsEmpty()
14 | && options->Has(key)
15 | ? options->Get(key)->BooleanValue()
16 | : def;
17 | }
18 |
19 | NAN_INLINE uint32_t UInt32OptionValue(v8::Local options,
20 | const char* _key,
21 | uint32_t def) {
22 | Nan::HandleScope scope;
23 | v8::Local key = Nan::New(_key).ToLocalChecked();
24 | return !options.IsEmpty()
25 | && options->Has(key)
26 | && options->Get(key)->IsNumber()
27 | ? options->Get(key)->Uint32Value()
28 | : def;
29 | }
30 |
31 | } // namespace leveldown
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/src/database.h:
--------------------------------------------------------------------------------
1 | #ifndef LD_DATABASE_H
2 | #define LD_DATABASE_H
3 |
4 | #include