Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store): Add new TreeMap implementation #665

Merged
merged 27 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
586f0f0
feat(store): TreeMap first steps in place to see initial changes
austinabell Dec 1, 2021
e174068
move to actual location
austinabell Dec 1, 2021
6437ec7
cleanups
austinabell Dec 1, 2021
ef41abd
wip before refactor
austinabell Dec 8, 2021
dfe3d8a
refactor to move tree functionality into own type
austinabell Dec 8, 2021
19819b2
refactor some internal functions
austinabell Dec 8, 2021
1d83338
finish impl. Has some failures still
austinabell Dec 8, 2021
7619f86
fix and refactor things, less failures
austinabell Dec 9, 2021
eda882d
fix other bug
austinabell Dec 9, 2021
f77b805
fix bug with insert delete insert pattern
austinabell Dec 9, 2021
e46fcfb
implement iterator functions, all tests passing
austinabell Dec 9, 2021
7e9c6d2
implement entry API
austinabell Dec 9, 2021
5f0c088
fix trait bounds on iter
austinabell Dec 9, 2021
911249c
add range iterator
austinabell Dec 9, 2021
c774cee
cleanup
austinabell Dec 9, 2021
c9ee932
Merge branch 'master' of github.com:near/near-sdk-rs into austin/stor…
austinabell Dec 9, 2021
76e66e8
more cleanup
austinabell Dec 9, 2021
274579c
split keys/keys range to get compile time guarantees and optimized fu…
austinabell Dec 10, 2021
dbe2851
range prop tests
austinabell Dec 10, 2021
c8af227
add missing get_key_value function
austinabell Dec 10, 2021
bc9f227
Merge branch 'master' into austin/store/treemap
austinabell Dec 10, 2021
6bb7ece
addr comments and cleanup
austinabell Jan 5, 2022
7e6ace5
addr cleanup comments
austinabell Jan 6, 2022
d711c3f
fix: remove redundant line
austinabell Jan 12, 2022
7854632
Merge branch 'master' of github.com:near/near-sdk-rs into austin/stor…
austinabell Jan 12, 2022
33324dc
update docs from old impl
austinabell Jan 12, 2022
bab2d1c
Merge branch 'master' into austin/store/treemap
austinabell Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion near-sdk/src/store/free_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{fmt, mem};

/// Index for value within a bucket.
#[derive(BorshSerialize, BorshDeserialize, Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub struct FreeListIndex(u32);
pub struct FreeListIndex(pub(crate) u32);

/// Unordered container of values. This is similar to [`Vector`] except that values are not
/// re-arranged on removal, keeping the indices consistent. When an element is removed, it will
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/lookup_map/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a, K, V> Entry<'a, K, V> {
/// use near_sdk::store::LookupMap;
///
/// let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
/// assert_eq!(map.entry("poneyland".to_string()).key(), &"poneyland");
/// assert_eq!(map.entry("poneyland".to_string()).key(), "poneyland");
/// ```
pub fn key(&self) -> &K {
match self {
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/lookup_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::marker::PhantomData;
use borsh::{BorshDeserialize, BorshSerialize};
use once_cell::unsync::OnceCell;

use super::ERR_NOT_EXIST;
use crate::crypto_hash::{CryptoHasher, Sha256};
use crate::utils::{EntryState, StableMap};
use crate::{env, CacheEntry, IntoStorageKey};
Expand All @@ -16,7 +17,6 @@ pub use entry::{Entry, OccupiedEntry, VacantEntry};

const ERR_ELEMENT_DESERIALIZATION: &str = "Cannot deserialize element";
const ERR_ELEMENT_SERIALIZATION: &str = "Cannot serialize element";
const ERR_NOT_EXIST: &str = "Key does not exist in map";

type LookupKey = [u8; 32];

Expand Down
11 changes: 9 additions & 2 deletions near-sdk/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ pub use self::lookup_set::LookupSet;
pub mod unordered_map;
pub use self::unordered_map::UnorderedMap;

pub mod tree_map;
pub use self::tree_map::TreeMap;

mod index_map;
pub(crate) use self::index_map::IndexMap;

pub(crate) mod free_list;
pub(crate) use self::free_list::FreeList;

const ERR_INCONSISTENT_STATE: &str = "The collection is an inconsistent state. Did previous smart \
contract execution terminate unexpectedly?";
pub(crate) const ERR_INCONSISTENT_STATE: &str =
"The collection is an inconsistent state. Did previous smart \
contract execution terminate unexpectedly?";

// TODO don't need crate pub once moved
pub(crate) const ERR_NOT_EXIST: &str = "Key does not exist in map";
Loading