Skip to content

Commit

Permalink
feat(store): Add new TreeMap implementation (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell authored Jan 13, 2022
1 parent 30397a2 commit 44d1976
Show file tree
Hide file tree
Showing 11 changed files with 3,397 additions and 11 deletions.
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 @@ -19,11 +19,18 @@ pub use self::unordered_map::UnorderedMap;
pub mod unordered_set;
pub use self::unordered_set::UnorderedSet;

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

0 comments on commit 44d1976

Please sign in to comment.