NIAOJoin Beta
Ecosystem

dsa

available

Data Structures & Algorithms

Core Standard Library

Overview

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.

  • Lists & deques
  • Hash maps & sets
  • Graphs & heaps
  • Fast native paths

Import

import
import "dsa"

Quick start

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")

Capabilities

High-level overview of what dsa is for.

Lists & deques

Linked list, stack (push/pop one end), queue (push back/pop front), deque (both ends). Pick the shape that matches your access pattern.

Hash maps & sets

Key-value map and unique-value set. Insert, lookup, and delete are amortized O(1) for typical loads.

Graphs & heaps

Add nodes and weighted edges; run BFS, DFS, or Dijkstra. Min/max heap for priority-queue style problems.

Array utilities

Sort in place, binary search on sorted data, reverse, operations on Niao list values.

API reference

92 functions and methods in dsa. Grouped by category from the standard library docs.

Linked list

SignatureDescription
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

Stack (LIFO)

SignatureDescription
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

Queue (FIFO)

SignatureDescription
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

Deque (double-ended queue)

SignatureDescription
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

Heap (priority queue)

SignatureDescription
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

Hash set

SignatureDescription
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`

Hash map

SignatureDescription
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

Construction

SignatureDescription
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

Algorithms

SignatureDescription
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

Array algorithms

SignatureDescription
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)

Related libraries

More from Core Standard Library.

available

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
Read more
available

io

File & Path I/O

Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.

  • Whole-file read/write
  • Streaming handles
  • Background I/O
  • Path helpers
Read more
available

time

Wall-Clock & Time Zones

Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.

  • IANA time zones
  • strftime formats
  • Datetime values
  • Date math
Read more