json
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
- parse & stringify
- Dot-path access
- Deep merge
- Pretty-print
Data Structures & Algorithms
Core Standard Library
dsa is the toolbox when the built-in list type isn't enough. Doubly-linked lists, stacks, queues, deques, hash maps, hash sets, binary heaps, and directed graphs, all implemented in Rust with sensible complexity on the operations you'd call in a loop.
Graphs support BFS, DFS, and Dijkstra for pathfinding. Array helpers cover sort, binary search, and reverse on ordinary Niao lists.
Import
import "dsa" |
Quick start
import "dsa" |
|
let g = dsa.graph() |
g.add_edge("A", "B", 1) |
g.add_edge("B", "C", 2) |
let path = g.dijkstra("A", "C") |
High-level overview of what dsa is for.
Linked list, stack (push/pop one end), queue (push back/pop front), deque (both ends). Pick the shape that matches your access pattern.
Key-value map and unique-value set. Insert, lookup, and delete are amortized O(1) for typical loads.
Add nodes and weighted edges; run BFS, DFS, or Dijkstra. Min/max heap for priority-queue style problems.
Sort in place, binary search on sorted data, reverse, operations on Niao list values.
92 functions and methods in dsa. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| list_new() | Empty list |
| list_from_array(arr) | Copy from array |
| list_push_front(l, v) | Prepend |
| list_push_back(l, v) | Append |
| list_pop_front(l) | nil |
| list_pop_back(l) | nil |
| list_front(l) | nil |
| list_back(l) | nil |
| list_get(l, i) | Index (bounds-checked) |
| list_set(l, i, v) | Replace at index |
| list_insert(l, i, v) | Insert before index (`i` may equal `len`) |
| list_remove(l, i) | Remove and return at index |
| list_contains(l, v) | Membership by value equality |
| list_index_of(l, v) | Index or `-1` |
| list_reverse(l) | Reverse in place |
| list_to_array(l) | Snapshot as array |
| list_clear(l) | Remove all elements |
| list_is_empty(l) | Whether empty |
| Signature | Description |
|---|---|
| stack_new() | Empty stack |
| stack_push(s, v) | Push on top |
| stack_pop(s) | nil |
| stack_peek(s) | nil |
| stack_is_empty(s) | Whether empty |
| stack_clear(s) | Remove all |
| stack_to_array(s) | Bottom-to-top snapshot |
| Signature | Description |
|---|---|
| queue_new() | Empty queue |
| queue_push(q, v) | Enqueue at back |
| queue_pop(q) | nil |
| queue_front(q) | nil |
| queue_back(q) | nil |
| queue_is_empty(q) | Whether empty |
| queue_clear(q) | Remove all |
| queue_to_array(q) | Front-to-back snapshot |
| Signature | Description |
|---|---|
| deque_new() | Empty deque |
| deque_push_front(d, v) | Prepend |
| deque_push_back(d, v) | Append |
| deque_pop_front(d) | nil |
| deque_pop_back(d) | nil |
| deque_front(d) | nil |
| deque_back(d) | nil |
| deque_is_empty(d) | Whether empty |
| deque_clear(d) | Remove all |
| deque_to_array(d) | Front-to-back snapshot |
| Signature | Description |
|---|---|
| heap_new_min() | Min-heap |
| heap_new_max() | Max-heap |
| heap_push(h, n) | Insert |
| heap_pop(h) | nil |
| heap_peek(h) | nil |
| heap_is_empty(h) | Whether empty |
| Signature | Description |
|---|---|
| set_new() | Empty set |
| set_from_array(arr) | Build from array (deduplicates) |
| set_add(s, key) | `true` if newly inserted |
| set_remove(s, key) | `true` if removed |
| set_contains(s, key) | Membership |
| set_is_empty(s) | Whether empty |
| set_clear(s) | Remove all |
| set_to_array(s) | Values in insertion order |
| set_union(a, b) | New set: elements in either |
| set_intersect(a, b) | New set: elements in both |
| set_diff(a, b) | New set: in `a` but not `b` |
| Signature | Description |
|---|---|
| map_new() | Empty map |
| map_set(m, key, value) | Insert or update |
| map_get(m, key) | nil |
| map_has(m, key) | Key exists |
| map_remove(m, key) | `true` if removed |
| map_keys(m) | Keys in insertion order |
| map_values(m) | Values in insertion order |
| map_is_empty(m) | Whether empty |
| map_clear(m) | Remove all |
| Signature | Description |
|---|---|
| graph_new(n) | Undirected graph with `n` nodes |
| graph_new_directed(n) | Directed graph with `n` nodes |
| graph_add_edge(g, u, v) | Add edge with weight `1` |
| graph_add_edge_w(g, u, v, w) | Add edge with weight `w` |
| graph_neighbors(g, u) | Adjacent node ids |
| graph_node_count(g) | Number of nodes |
| graph_edge_count(g) | Number of edges added |
| Signature | Description |
|---|---|
| graph_bfs(g, src) | BFS visit order from `src` |
| graph_dfs(g, src) | DFS visit order from `src` |
| graph_dijkstra(g, src) | Shortest distances from `src`; unreachable nodes are `-1` |
| graph_topo_sort(g) | nil |
| Signature | Description |
|---|---|
| push(arr, v) | Append (promotes int array to generic array if needed) |
| pop(arr) | nil |
| sort(arr) | Ascending sort in place |
| sort_desc(arr) | Descending sort in place |
| binary_search(arr, target) | Index in sorted array, or `-1` |
| reverse(arr) | Reverse in place |
| sum(arr) | Sum of numeric elements |
| min(arr) | nil |
| max(arr) | nil |
| index_of(arr, v) | First index or `-1` |
| contains(arr, v) | Whether `index_of >= 0` |
| unique(arr) | New array with duplicates removed (hashable keys first; linear scan fallback) |
More from Core Standard Library.
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
File & Path I/O
Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.
Wall-Clock & Time Zones
Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.