tree

package
v0.0.0-...-ca7ee28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

README

tree

This project implements a simple tree in the Go Language. The code is taken from Tufin's repository, with some small modifications:

  • For method Add, the argument path is a []string (instead of a string to be split on the '/' character)
  • User-passed functions are called depending on whether a node is absent or present in the tree.
Example
import (radix "github.com/Emeline-1/tree")

func generate_if_present (w *bufio.Writer) func (string, interface{}) {
    return func (element string, arg interface{}) {
    	w.WriteString (element + " is present")
    }
}

func generate_if_absent (w *bufio.Writer) func (string, interface{}) {
    return func (element string, arg interface{}) {
        w.WriteString (element + " is absent")
    }
}

func main () {
    f, _ := os.Create(filename) 
    defer f.Close ()
    w := bufio.NewWriter(f)
    f_absent := generate_if_absent (w)
    f_present := generate_if_present (w)

    path_tree := &tree.Tree{}
    path_tree.Add (["1", "2", "3"], f_absent, f_present, nil)
    path_tree.Add (["1", "2", "4"], f_absent, f_present, nil)
}

In this example, f_absent will be called on elements "1", "2", and "3". Then f_present will be called on elements "1" and "2". And finally, f_absent will be called on element "4".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoxType

type BoxType int
const (
	Regular BoxType = iota
	Last
	AfterLast
	Between
)

func (BoxType) String

func (boxType BoxType) String() string

type Tree

type Tree map[string]Tree

Tree can be any map with: 1. Key that has method 'String() string' 2. Value is Tree itself You can replace this with your own tree

func (Tree) Add

func (tree Tree) Add(path []string, if_absent, if_present func(string, interface{}), arg interface{})

*

  • Adds paths to the tree, and call if_absent on current element if
  • it is not present in the current path.

func (Tree) Fprint

func (tree Tree) Fprint(w io.Writer, root bool, padding string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL