Skip to content

Commit 193181a

Browse files
committed
seperated into modules
1 parent 04b8c1c commit 193181a

Some content is hidden

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

52 files changed

+11544
-11238
lines changed

Diff for: README.md

+12-25
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ A Rust implementation of a map data structure backed by a trie (prefix tree).
44

55
## Features
66

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-
## Documentation
14-
15-
Full API documentation is available at: https://ekinimo.github.io/triemap
7+
- Key lookups with O(k) complexity where k is the key length
8+
- Prefix-based operations for finding and manipulating keys with a common prefix
9+
- API similar to Rust's standard collections
10+
- Iterator support
11+
- Entry API for efficient updates
1612

1713
## Usage
1814

@@ -54,7 +50,7 @@ assert_eq!(map.get("cherry"), None);
5450

5551
### Prefix Operations
5652

57-
One of TrieMap's strengths is working with key prefixes:
53+
Working with key prefixes:
5854

5955
```rust
6056
use triemap::TrieMap;
@@ -114,7 +110,7 @@ map.insert("b", 2);
114110
map.insert("c", 3);
115111

116112
// Iterate over key-value pairs
117-
for (key, value) in &map {
113+
for (key, value) in map.iter() {
118114
println!("{}: {}", String::from_utf8_lossy(&key), value);
119115
}
120116

@@ -134,7 +130,7 @@ for value in map.values_mut() {
134130
}
135131
```
136132

137-
### Set Operations
133+
### Set-like Operations
138134

139135
```rust
140136
use triemap::TrieMap;
@@ -147,19 +143,10 @@ let mut map2 = TrieMap::new();
147143
map2.insert("b", 20);
148144
map2.insert("c", 30);
149145

150-
// Intersection
151-
let intersection = map1.intersect_ref(&map2);
152-
assert_eq!(intersection.len(), 1);
153-
assert_eq!(intersection.get("b"), Some(&2));
154-
155-
// Difference
156-
let difference = map1.difference_ref(&map2);
157-
assert_eq!(difference.len(), 1);
158-
assert_eq!(difference.get("a"), Some(&1));
159-
160-
// Union
161-
let union = map1.clone().union(map2.clone());
162-
assert_eq!(union.len(), 3);
146+
// Union, difference, intersect operations
147+
let union: Vec<_> = map1.union(&map2).collect();
148+
let difference: Vec<_> = map1.difference(&map2).collect();
149+
let intersection: Vec<_> = map1.intersect(&map2).collect();
163150
```
164151

165152
## Contributing

Diff for: docs/search-index.js

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

Diff for: docs/search.desc/triemap/triemap-desc-0-.js

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

Diff for: docs/src-files.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
var srcIndex = new Map(JSON.parse('[["triemap",["",[],["lib.rs"]]]]'));
1+
var srcIndex = new Map(JSON.parse('[["triemap",["",[],["as_bytes.rs","entry.rs","iter.rs","lib.rs","node.rs","trie_map.rs"]]],["triemap",["",[],["lib.rs"]]]]'));
22
createSrcSidebar();
3-
//{"start":36,"fragment_lengths":[30]}
3+
//{"start":36,"fragment_lengths":[89,31]}

Diff for: docs/src/triemap/as_bytes.rs.html

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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="Source of the Rust file `src/as_bytes.rs`."><title>as_bytes.rs - source</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/src-script-56102188.js"></script><script defer src="../../src-files.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="src-sidebar-title"><h2>Files</h2></div></nav><div class="sidebar-resizer"></div><main><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1><div class="sub-heading">triemap/</div>as_bytes.rs</h1><rustdoc-toolbar></rustdoc-toolbar></div><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers">
2+
<a href="#1" id="1">1</a>
3+
<a href="#2" id="2">2</a>
4+
<a href="#3" id="3">3</a>
5+
<a href="#4" id="4">4</a>
6+
<a href="#5" id="5">5</a>
7+
<a href="#6" id="6">6</a>
8+
<a href="#7" id="7">7</a>
9+
<a href="#8" id="8">8</a>
10+
<a href="#9" id="9">9</a>
11+
<a href="#10" id="10">10</a>
12+
<a href="#11" id="11">11</a>
13+
<a href="#12" id="12">12</a>
14+
<a href="#13" id="13">13</a>
15+
<a href="#14" id="14">14</a>
16+
<a href="#15" id="15">15</a>
17+
<a href="#16" id="16">16</a>
18+
<a href="#17" id="17">17</a>
19+
<a href="#18" id="18">18</a>
20+
<a href="#19" id="19">19</a>
21+
<a href="#20" id="20">20</a>
22+
<a href="#21" id="21">21</a>
23+
<a href="#22" id="22">22</a>
24+
<a href="#23" id="23">23</a>
25+
<a href="#24" id="24">24</a>
26+
<a href="#25" id="25">25</a>
27+
<a href="#26" id="26">26</a>
28+
<a href="#27" id="27">27</a>
29+
<a href="#28" id="28">28</a>
30+
<a href="#29" id="29">29</a>
31+
<a href="#30" id="30">30</a>
32+
<a href="#31" id="31">31</a>
33+
<a href="#32" id="32">32</a>
34+
<a href="#33" id="33">33</a>
35+
<a href="#34" id="34">34</a>
36+
<a href="#35" id="35">35</a>
37+
<a href="#36" id="36">36</a>
38+
<a href="#37" id="37">37</a>
39+
<a href="#38" id="38">38</a>
40+
<a href="#39" id="39">39</a>
41+
<a href="#40" id="40">40</a>
42+
<a href="#41" id="41">41</a>
43+
<a href="#42" id="42">42</a>
44+
<a href="#43" id="43">43</a>
45+
<a href="#44" id="44">44</a>
46+
<a href="#45" id="45">45</a>
47+
<a href="#46" id="46">46</a>
48+
<a href="#47" id="47">47</a>
49+
<a href="#48" id="48">48</a></pre></div><pre class="rust"><code><span class="doccomment">/// The `AsBytes` trait allows a type to be used as a key in a `TrieMap`.
50+
///
51+
/// It provides a method to convert the type to a byte slice.
52+
///
53+
</span><span class="kw">pub trait </span>AsBytes {
54+
<span class="doccomment">/// Converts the value to a byte slice.
55+
</span><span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8];
56+
57+
<span class="kw">fn </span>as_bytes_vec(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Vec&lt;u8&gt; {
58+
<span class="self">self</span>.as_bytes().into()
59+
}
60+
}
61+
62+
<span class="kw">impl </span>AsBytes <span class="kw">for </span>[u8] {
63+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
64+
<span class="self">self
65+
</span>}
66+
}
67+
68+
<span class="kw">impl </span>AsBytes <span class="kw">for </span>Vec&lt;u8&gt; {
69+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
70+
<span class="self">self
71+
</span>}
72+
}
73+
74+
<span class="kw">impl </span>AsBytes <span class="kw">for </span>str {
75+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
76+
str::as_bytes(<span class="self">self</span>)
77+
}
78+
}
79+
80+
<span class="kw">impl </span>AsBytes <span class="kw">for </span>String {
81+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
82+
<span class="self">self</span>.as_str().as_bytes()
83+
}
84+
}
85+
86+
<span class="kw">impl</span>&lt;T: AsBytes + <span class="question-mark">?</span>Sized&gt; AsBytes <span class="kw">for </span><span class="kw-2">&amp;</span>T {
87+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
88+
T::as_bytes(<span class="kw-2">*</span><span class="self">self</span>)
89+
}
90+
}
91+
92+
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; AsBytes <span class="kw">for </span>[u8; N] {
93+
<span class="kw">fn </span>as_bytes(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
94+
<span class="self">self</span>.as_slice()
95+
}
96+
}
97+
</code></pre></div></section></main></body></html>

0 commit comments

Comments
 (0)