aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-10-26 20:35:04 -0700
committerBryan Newbold <bnewbold@robocracy.org>2017-10-26 20:35:04 -0700
commitd1d9c5780820e1be44a44bb48c27d5afd0af5c69 (patch)
tree927c26e31528b23ec80512f167fc53b94d8e3704
parentd95adfa86a4a903a20120a93b8d10ae39fb6cd3d (diff)
downloadgeniza-d1d9c5780820e1be44a44bb48c27d5afd0af5c69.tar.gz
geniza-d1d9c5780820e1be44a44bb48c27d5afd0af5c69.zip
implement trivial dense (not sparse) has() on register
-rw-r--r--src/register.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/register.rs b/src/register.rs
index 8fc3a6f..f04e2e2 100644
--- a/src/register.rs
+++ b/src/register.rs
@@ -318,9 +318,10 @@ impl SleepDirRegister {
impl HyperRegister for SleepDirRegister {
- fn has(&self, _index: u64) -> Result<bool> {
- // looks in bitfield
- unimplemented!()
+ /// TODO: this version only works for "dense" registers: it just checks if the index is in the
+ /// total length, instead of using the bitfield.
+ fn has(&self, index: u64) -> Result<bool> {
+ return Ok(index < self.len()?);
}
fn has_all(&self) -> Result<bool> {
@@ -482,9 +483,7 @@ fn test_sdr_open() {
fn test_sdr_create() {
use tempdir::TempDir;
-
let tmp_dir = TempDir::new("geniza-test").unwrap();
-
let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
assert_eq!(sdr.len().unwrap(), 0);
@@ -495,9 +494,7 @@ fn test_sdr_create() {
fn test_sdr_append() {
use tempdir::TempDir;
-
let tmp_dir = TempDir::new("geniza-test").unwrap();
-
let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
sdr.append("hello world!".as_bytes()).unwrap();
@@ -512,3 +509,17 @@ fn test_sdr_append() {
assert_eq!(sdr.len().unwrap(), 1+count);
assert_eq!(sdr.len_bytes().unwrap(), 12 + (count*5));
}
+
+#[test]
+fn test_sdr_has() {
+
+ use tempdir::TempDir;
+ let tmp_dir = TempDir::new("geniza-test").unwrap();
+ let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
+
+ sdr.append("hello world!".as_bytes()).unwrap();
+ sdr.check().unwrap();
+ assert_eq!(sdr.has_all().unwrap(), true);
+ assert_eq!(sdr.has(0).unwrap(), true);
+ assert_eq!(sdr.has(40).unwrap(), false);
+}