Mercurial > lbo > hg > sstable
changeset 6:df70324cb053
Even more comments and auxiliary constructs
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 19 Nov 2016 14:18:32 +0100 |
parents | b2891489832c |
children | cefb88d2c262 |
files | Cargo.toml src/table_builder.rs src/table_reader.rs |
diffstat | 3 files changed, 33 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.toml Sat Nov 19 14:06:36 2016 +0100 +++ b/Cargo.toml Sat Nov 19 14:18:32 2016 +0100 @@ -1,7 +1,11 @@ [package] name = "sstable" +description = "Sorted String Tables, an on-disk format for storing immutable maps consisting of string,string pairs, and retrieving values by key efficiently." version = "0.1.0" -authors = ["Lewin Bormann <lewin@lewin-bormann.info>"] +readme = "README.md" +keywords = ["sstable", "database"] +repository = "https://bitbucket.org/dermesser/sstable" +authors = ["Lewin Bormann <lbo@spheniscida.de>"] license = "MIT" [dependencies]
--- a/src/table_builder.rs Sat Nov 19 14:06:36 2016 +0100 +++ b/src/table_builder.rs Sat Nov 19 14:18:32 2016 +0100 @@ -1,7 +1,7 @@ use block::{BlockBuilder, BlockContents}; use blockhandle::BlockHandle; use options::{CompressionType, Options}; -use iterator::Comparator; +use iterator::{Comparator, StandardComparator}; use std::io::Write; use std::cmp::Ordering; @@ -98,7 +98,17 @@ index_block: Option<BlockBuilder<C>>, } +impl<Dst: Write> TableBuilder<StandardComparator, Dst> { + + /// Create a new TableBuilder with default comparator and options. + pub fn new_defaults(dst: Dst) -> TableBuilder<StandardComparator, Dst> { + TableBuilder::new(Options::default(), StandardComparator, dst) + } +} + impl<C: Comparator, Dst: Write> TableBuilder<C, Dst> { + + /// Create a new TableBuilder. pub fn new(opt: Options, cmp: C, dst: Dst) -> TableBuilder<C, Dst> { TableBuilder { o: opt, @@ -112,6 +122,7 @@ } } + /// Returns how many entries have been written. pub fn entries(&self) -> usize { self.num_entries } @@ -178,6 +189,8 @@ handle } + /// Finish building this table. This *must* be called at the end, otherwise not all data may + /// land on disk. pub fn finish(mut self) { assert!(self.data_block.is_some()); let ctype = self.o.compression_type;
--- a/src/table_reader.rs Sat Nov 19 14:06:36 2016 +0100 +++ b/src/table_reader.rs Sat Nov 19 14:18:32 2016 +0100 @@ -1,7 +1,7 @@ use block::{Block, BlockContents, BlockIter}; use blockhandle::BlockHandle; use table_builder::{self, Footer}; -use iterator::{Comparator, SSIterator}; +use iterator::{Comparator, StandardComparator, SSIterator}; use integer_encoding::FixedInt; use crc::crc32; @@ -44,7 +44,16 @@ indexblock: Block<C>, } +impl<R: Read + Seek> Table<R, StandardComparator> { + /// Open a table for reading. + pub fn new_defaults(file: R, size: usize) -> Result<Table<R, StandardComparator>> { + Table::new(file, size, StandardComparator) + } +} + impl<R: Read + Seek, C: Comparator> Table<R, C> { + /// Open a table for reading. Note: The comparator must be the same that was chosen when + /// building the table. pub fn new(mut file: R, size: usize, cmp: C) -> Result<Table<R, C>> { let footer = try!(read_footer(&mut file, size)); @@ -87,6 +96,10 @@ iter } + /// Retrieve an entry from the table. + /// + /// Note: As this doesn't keep state, using a TableIterator and seek() may be more efficient + /// when retrieving several entries from the same underlying block. pub fn get(&mut self, key: &[u8]) -> Option<Vec<u8>> { let mut iter = self.iter();