Skip to content

dmyTRUEk/btree-nixla

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

Some binary tree operations using nixla

yeah, fun

Examples:

Example 1: tokens

btree.nix at 7244c4a:

$ nixla-nix btree-7244c4a.nix '(a b c)'
[ "(" "a" "b" "c" ")" ]

Example 2: tree

btree.nix at 74f7f64:

$ nixla-nix btree-74f7f64.nix '(a b c)'
{ data = "a"; left = "b"; right = "c"; }

Example 3: tree to indented string

btree.nix at f9c2dae:

$ nixla btree-f9c2dae.nix '(a (b 1 2) (c 3 (d (e 7 8) 6)))'
a
  b
    1
    2
  c
    3
    d
      e
        7
        8
      6

Example 4: reverse tree

btree.nix at deb6d86:

$ nixla btree-deb6d86.nix '(a (b 1 2) (c 3 (d (e 7 8) 6)))'
a
  c
    d
      6
      e
        8
        7
    3
  b
    2
    1

Example 5: traverse tree

main.nix at b0ed48a

# main-b0ed48a.nix
...
tree_dfs_preorder = tree:
  if !isAttrs tree then
    [tree]
  else
    [tree.data] ++
    tree_dfs_preorder tree.left ++
    tree_dfs_preorder tree.right
;
...
$ nixla-nix main-b0ed48a.nix '(a (b 1 2) (c 3 (d (e 7 8) 6)))'
[ "a" "b" "1" "2" "c" "3" "d" "e" "7" "8" "6" ]

About

BTree operations using nixla

Topics

Resources

Stars

Watchers

Forks

Languages