RpdsPy¶
Description:
- Python bindings to the Rust rpds crate for persistent data structures.
Resources:
- [GitHub] https://github.com/crate-py/rpds
- [Rust Crate Docs] https://docs.rs/rpds/latest/rpds/
Example 1¶
Create a hash trie map
In [ ]:
Copied!
from rpds import HashTrieMap
m = HashTrieMap({"foo": "bar", "baz": "quux"})
m.insert("spam", 37) == HashTrieMap({"foo": "bar", "baz": "quux", "spam": 37})
m.remove("foo") == HashTrieMap({"baz": "quux"})
from rpds import HashTrieMap
m = HashTrieMap({"foo": "bar", "baz": "quux"})
m.insert("spam", 37) == HashTrieMap({"foo": "bar", "baz": "quux", "spam": 37})
m.remove("foo") == HashTrieMap({"baz": "quux"})
Example 2¶
Create a hash trie set
In [ ]:
Copied!
from rpds import HashTrieSet
s = HashTrieSet({"foo", "bar", "baz", "quux"})
s.insert("spam") == HashTrieSet({"foo", "bar", "baz", "quux", "spam"})
s.remove("foo") == HashTrieSet({"bar", "baz", "quux"})
from rpds import HashTrieSet
s = HashTrieSet({"foo", "bar", "baz", "quux"})
s.insert("spam") == HashTrieSet({"foo", "bar", "baz", "quux", "spam"})
s.remove("foo") == HashTrieSet({"bar", "baz", "quux"})
Example 3¶
Create a list
In [ ]:
Copied!
from rpds import List
L = List([1, 3, 5])
L.push_front(-1) == List([-1, 1, 3, 5])
L.rest == List([3, 5])
from rpds import List
L = List([1, 3, 5])
L.push_front(-1) == List([-1, 1, 3, 5])
L.rest == List([3, 5])