Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
815d8a7
.
dragoljub-djuric Feb 26, 2024
c256be9
Merge branch 'main' into EXC-1384-add-stable-b-tree-set-in-stable-str…
dragoljub-djuric Mar 14, 2024
86ddec1
.
dragoljub-djuric Mar 19, 2024
948393f
fix test
dragoljub-djuric Mar 19, 2024
3484ff6
clippy
dragoljub-djuric Mar 19, 2024
2e1f509
refactor
dragoljub-djuric Mar 19, 2024
e0518ed
Merge branch 'main' into EXC-1384-add-stable-b-tree-set-in-stable-str…
dragoljub-djuric Apr 23, 2025
e245d9b
.
dragoljub-djuric Apr 25, 2025
6ff4a33
.
dragoljub-djuric Apr 25, 2025
dde8267
.
dragoljub-djuric Apr 25, 2025
9615d6c
.
dragoljub-djuric Apr 25, 2025
e3d31cb
.
dragoljub-djuric Apr 25, 2025
9386c45
.
dragoljub-djuric Apr 25, 2025
53fa85e
.
dragoljub-djuric Apr 25, 2025
a169923
.
dragoljub-djuric Apr 25, 2025
198e1e8
.
dragoljub-djuric Apr 25, 2025
8e9ae09
.
dragoljub-djuric Apr 28, 2025
cb258ea
Merge branch 'main' into EXC-1384-add-stable-b-tree-set-in-stable-str…
dragoljub-djuric Apr 28, 2025
58332f0
.
dragoljub-djuric Apr 28, 2025
d720fa2
.
dragoljub-djuric Apr 28, 2025
17534a1
.
dragoljub-djuric Apr 28, 2025
5cf86f5
.
dragoljub-djuric Apr 28, 2025
2393c00
.
dragoljub-djuric Apr 28, 2025
308e1d9
.
dragoljub-djuric Apr 28, 2025
7b55e60
.
dragoljub-djuric Apr 29, 2025
481741e
Update src/btreeset.rs
dragoljub-djuric Apr 29, 2025
147d88c
.
dragoljub-djuric Apr 29, 2025
176192e
Revert canbench_results.yml change.
dragoljub-djuric Apr 29, 2025
cd4735e
Add comment explaining relation of BTreeSet and BTreeMap.
dragoljub-djuric Apr 29, 2025
ab02321
Optimize intersection function.
dragoljub-djuric Apr 29, 2025
f4bf556
Comment union and intersection functions.
dragoljub-djuric Apr 29, 2025
8ea02aa
fix clippy error.
dragoljub-djuric Apr 29, 2025
62a7e5b
.
dragoljub-djuric Apr 29, 2025
666c153
Revert "."
dragoljub-djuric Apr 29, 2025
75b962b
remove redundant tests
dragoljub-djuric Apr 29, 2025
8f2caca
Merge branch 'main' into EXC-1384-add-stable-b-tree-set-in-stable-str…
dragoljub-djuric Apr 29, 2025
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
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For more information about the philosophy behind the library, see [Roman's tutor
## Available Data Structures

- [BTreeMap]: A Key-Value store
- [BTreeSet]: A set of unique elements
- [Vec]: A growable array
- [Log]: An append-only list of variable-size entries
- [Cell]: A serializable value
Expand All @@ -38,7 +39,9 @@ Stable structures are able to work directly in stable memory because each data s
its own memory.
When initializing a stable structure, a memory is provided that the data structure can use to store its data.

Here's a basic example:
Here's a basic examples:

### Example: BTreeMap

```rust
use ic_stable_structures::{BTreeMap, DefaultMemoryImpl};
Expand All @@ -54,12 +57,25 @@ This includes stable memory, a vector ([VectorMemory]), or even a flat file ([Fi

The example above initializes a [BTreeMap] with a [DefaultMemoryImpl], which maps to stable memory when used in a canister and to a [VectorMemory] otherwise.

### Example: BTreeSet

The `BTreeSet` is a stable set implementation based on a B-Tree. It allows efficient insertion, deletion, and lookup of unique elements.

```rust
use ic_stable_structures::{BTreeSet, DefaultMemoryImpl};
let mut set: BTreeSet<u64, _> = BTreeSet::new(DefaultMemoryImpl::default());

set.insert(42);
assert!(set.contains(&42));
assert_eq!(set.pop_first(), Some(42));
assert!(set.is_empty());
```


Note that **stable structures cannot share memories.**
Each memory must belong to only one stable structure.
For example, this fails when run in a canister:


```no_run
use ic_stable_structures::{BTreeMap, DefaultMemoryImpl};
let mut map_1: BTreeMap<u64, u64, _> = BTreeMap::init(DefaultMemoryImpl::default());
Expand Down
Loading