Skip to content

Commit 29fa6a1

Browse files
committed
docs
1 parent 854e37f commit 29fa6a1

File tree

79 files changed

+12848
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+12848
-0
lines changed

Diff for: LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 ekinimo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# TrieMap
2+
3+
A Rust implementation of a map data structure backed by a trie (prefix tree).
4+
5+
## Features
6+
7+
- Fast key lookups with O(k) complexity where k is the key length
8+
- Prefix-based operations (matching keys with a common prefix)
9+
- Intuitive API similar to Rust's standard collections
10+
- Full iterator support
11+
- Entry API for in-place updates
12+
13+
## Usage
14+
15+
Add to your `Cargo.toml`:
16+
17+
```toml
18+
[dependencies]
19+
triemap = { git = "https://github.com/yourusername/triemap" }
20+
```
21+
22+
### Basic Operations
23+
24+
```rust
25+
use triemap::TrieMap;
26+
27+
// Create a new map
28+
let mut map = TrieMap::new();
29+
30+
// Insert key-value pairs
31+
map.insert("apple", 1);
32+
map.insert("banana", 2);
33+
map.insert("cherry", 3);
34+
35+
// Check if a key exists
36+
assert!(map.contains_key("apple"));
37+
assert!(!map.contains_key("grape"));
38+
39+
// Get a value
40+
assert_eq!(map.get("banana"), Some(&2));
41+
42+
// Update a value
43+
map.insert("apple", 10);
44+
assert_eq!(map.get("apple"), Some(&10));
45+
46+
// Remove a value
47+
assert_eq!(map.remove("cherry"), Some(3));
48+
assert_eq!(map.get("cherry"), None);
49+
```
50+
51+
### Prefix Operations
52+
53+
One of TrieMap's strengths is working with key prefixes:
54+
55+
```rust
56+
use triemap::TrieMap;
57+
58+
let mut map = TrieMap::new();
59+
map.insert("apple", 1);
60+
map.insert("application", 2);
61+
map.insert("banana", 3);
62+
63+
// Check if any keys start with a prefix
64+
assert!(map.starts_with("app"));
65+
66+
// Get all key-value pairs with a certain prefix
67+
let matches = map.get_prefix_matches("app");
68+
assert_eq!(matches.len(), 2);
69+
70+
// Iterate over keys with a prefix
71+
for key in map.prefix_keys("app") {
72+
println!("Key: {}", String::from_utf8_lossy(&key));
73+
}
74+
75+
// Remove all keys with a prefix
76+
let removed = map.remove_prefix_matches("app");
77+
assert_eq!(removed.len(), 2);
78+
```
79+
80+
### Entry API
81+
82+
```rust
83+
use triemap::{TrieMap, Entry};
84+
85+
let mut map = TrieMap::new();
86+
87+
// Insert a value if the key doesn't exist
88+
map.entry("a").or_insert(1);
89+
90+
// Update a value if the key exists
91+
match map.entry("a") {
92+
Entry::Occupied(mut entry) => {
93+
*entry.get_mut() += 10;
94+
}
95+
Entry::Vacant(_) => {}
96+
}
97+
98+
// Or more concisely:
99+
*map.entry("a").or_insert(0) += 5;
100+
```
101+
102+
### Iterators
103+
104+
```rust
105+
use triemap::TrieMap;
106+
107+
let mut map = TrieMap::new();
108+
map.insert("a", 1);
109+
map.insert("b", 2);
110+
map.insert("c", 3);
111+
112+
// Iterate over key-value pairs
113+
for (key, value) in &map {
114+
println!("{}: {}", String::from_utf8_lossy(&key), value);
115+
}
116+
117+
// Iterate over keys
118+
for key in map.keys() {
119+
println!("Key: {}", String::from_utf8_lossy(&key));
120+
}
121+
122+
// Iterate over values
123+
for value in map.values() {
124+
println!("Value: {}", value);
125+
}
126+
127+
// Mutable iteration
128+
for value in map.values_mut() {
129+
*value *= 2;
130+
}
131+
```
132+
133+
### Set Operations
134+
135+
```rust
136+
use triemap::TrieMap;
137+
138+
let mut map1 = TrieMap::new();
139+
map1.insert("a", 1);
140+
map1.insert("b", 2);
141+
142+
let mut map2 = TrieMap::new();
143+
map2.insert("b", 20);
144+
map2.insert("c", 30);
145+
146+
// Intersection
147+
let intersection = map1.intersect_ref(&map2);
148+
assert_eq!(intersection.len(), 1);
149+
assert_eq!(intersection.get("b"), Some(&2));
150+
151+
// Difference
152+
let difference = map1.difference_ref(&map2);
153+
assert_eq!(difference.len(), 1);
154+
assert_eq!(difference.get("a"), Some(&1));
155+
156+
// Union
157+
let union = map1.clone().union(map2.clone());
158+
assert_eq!(union.len(), 3);
159+
```
160+
161+
## Contributing
162+
163+
Contributions are welcome! Here are some ways you can contribute:
164+
165+
- Improve documentation
166+
- Add new features
167+
- Fix bugs
168+
- Optimize performance
169+
- Add more tests
170+
171+
Please feel free to submit issues and pull requests.
172+
173+
## License
174+
175+
This project is licensed under the MIT License - see the LICENSE file for details.

Diff for: docs/.lock

Whitespace-only changes.

Diff for: docs/crates.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
window.ALL_CRATES = ["triemap"];
2+
//{"start":21,"fragment_lengths":[9]}

Diff for: docs/help.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Documentation for Rustdoc"><title>Help</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="./static.files/${f}">`).join(""))</script><link rel="stylesheet" href="./static.files/normalize-9960930a.css"><link rel="stylesheet" href="./static.files/rustdoc-46132b98.css"><meta name="rustdoc-vars" data-root-path="./" data-static-root-path="./static.files/" data-current-crate="triemap" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.1 (4eb161250 2025-03-15)" data-channel="1.85.1" data-search-js="search-75f5ac3e.js" data-settings-js="settings-0f613d39.js" ><script src="./static.files/storage-59e33391.js"></script><script defer src="./static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="./static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="./static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="./static.files/favicon-044be391.svg"></head><body class="rustdoc mod sys"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-9a9549ea.svg" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="./index.html"><img class="rust-logo" src="./static.files/rust-logo-9a9549ea.svg" alt="logo"></a><h2><a href="./index.html">Rustdoc</a><span class="version">1.85.1</span></h2></div><div class="version">(4eb161250 2025-03-15)</div><h2 class="location">Help</h2><div class="sidebar-elems"></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Rustdoc help</h1><span class="out-of-band"><a id="back" href="javascript:void(0)" onclick="history.back();">Back</a></span></div><noscript><section><p>You need to enable JavaScript to use keyboard commands or search.</p><p>For more information, browse the <a href="https://doc.rust-lang.org/rustdoc/">rustdoc handbook</a>.</p></section></noscript></section></div></main></body></html>

Diff for: docs/search-index.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)