From d1d9c5780820e1be44a44bb48c27d5afd0af5c69 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 26 Oct 2017 20:35:04 -0700 Subject: implement trivial dense (not sparse) has() on register --- src/register.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/register.rs') 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 { - // 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 { + return Ok(index < self.len()?); } fn has_all(&self) -> Result { @@ -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); +} -- cgit v1.2.3