-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::base_storage::BaseStorage; | ||
use jni::sys::jlong; | ||
use std::cell::RefCell; | ||
use std::collections::btree_map::Iter; | ||
use std::rc::Rc; | ||
|
||
pub struct WrapperBTreeMap<'a, K, V> { | ||
data: Rc<RefCell<Iter<'a, K, V>>>, | ||
} | ||
|
||
impl<'a, K, V> WrapperBTreeMap<'a, K, V> | ||
where | ||
K: Ord + Clone, | ||
V: Clone, | ||
{ | ||
pub fn new<S: BaseStorage<K, V>>(storage: &'a S) -> Self { | ||
WrapperBTreeMap { | ||
data: Rc::new(RefCell::new(storage.as_ref().iter())), | ||
} | ||
} | ||
|
||
pub fn has_next(&self) -> bool { | ||
let borrow = self.data.borrow_mut(); | ||
borrow.clone().peekable().peek().is_some() | ||
} | ||
|
||
pub fn native_next(&mut self) -> Option<(K, V)> { | ||
let mut borrow = self.data.borrow_mut(); | ||
borrow.next().map(|(k, v)| (k.clone(), v.clone())) | ||
} | ||
|
||
pub fn from_jlong(value: jlong) -> &'a mut Self { | ||
unsafe { &mut *(value as *mut WrapperBTreeMap<K, V>) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod btree_wrapper; | ||
pub mod file_storage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.jar | ||
*.jar | ||
*.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
|
||
public class FileStorageIterator implements Iterator<Map.Entry<String, String>>, AutoCloseable { | ||
private long fileStorageIteratorPtr; | ||
|
||
private static native boolean hasNext(long file_storage_iterator_ptr); | ||
|
||
private static native Object next(long file_storage_iterator_ptr); | ||
|
||
private static native void destroyIterator(long file_storage_iterator_ptr); | ||
|
||
FileStorageIterator(long fileStorageIteratorPtr) { | ||
this.fileStorageIteratorPtr = fileStorageIteratorPtr; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return hasNext(this.fileStorageIteratorPtr); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Map.Entry<String, String> next() { | ||
if (!hasNext()) { | ||
throw new NoSuchElementException(); | ||
} | ||
return (Map.Entry<String, String>) next(this.fileStorageIteratorPtr); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (this.fileStorageIteratorPtr != 0) { | ||
destroyIterator(this.fileStorageIteratorPtr); | ||
this.fileStorageIteratorPtr = 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.