nuxScript

📦 Estruturas Exclusivas

Tuple, Set, Dict, Tree, Heap, Graph

Tuple (imutável)

let t = tuple(1, 2, 3)
tuple_get(t, 0)        // 1
tuple_len(t)           // 3
tuple_first(t)          // 1
tuple_last(t)          // 3
tuple_map(t, fn(x) => x * 2)  // tuple(2, 4, 6)
tuple_zip(t1, t2)      // tuple([1, 4], [2, 5])

Set

let s = set([1, 2, 3])
set_add(s, 4)
set_has(s, 2)         // true
set_delete(s, 1)
set_union(a, b)
set_intersect(a, b)
set_diff(a, b)

Dict

let d = dict({name: "John", age: 30})
dict_get(d, "name")           // "John"
dict_set(d, "city", "NYC")    // {name: "John", age: 30, city: "NYC"}
dict_keys(d)                  // ["name", "age", "city"]
dict_values(d)               // ["John", 30, "NYC"]
dict_merge(a, b)

Tree

let leaf = tree_leaf(42)
let root = tree_node(1, 
    tree_node(2),
    tree_node(3)
)

tree_map(root, fn(x) => x * 2)
tree_find(root, fn(x) => x > 1)
tree_depth(root)         // 2
tree_size(root)          // 3

Heap

let minheap = heap_min()
heap_push(minheap, 5)
heap_push(minheap, 2)
heap_push(minheap, 8)
heap_pop(minheap)        // 2
heap_peek(minheap)       // 5

let maxheap = heap_max()

Graph

let g = graph()
graph_add_node(g, "A")
graph_add_edge(g, "A", "B", 1)
graph_add_edge(g, "B", "C")

graph_bfs(g, "A")       // ["A", "B", "C"]
graph_dfs(g, "A")       // ["A", "B", "C"]
let result = graph_dijkstra(g, "A", "C")