Golang package for MPTT (Modified Preorder Tree Traversal) - materialized path realisation.

mpath-go

Go Report Card CircleCI codecov

Golang realisation of MPTT (or modified preorder tree traversal) in materialized path way.

About

It provides interfaces which yor database object should implement.

Your database object should store:

  • path property as slice of uint64 IDs of materialized path to this object in traversal tree;
  • position property as integer for determine the order of leafs in tree

Usage

Implementation example and tests are in test file.

package main

import (
    "fmt"

    "github.com/spacetab-io/mpath"
)

type TestItems []*TestItem

type TestItem struct {
    ID       uint64
    Path     []uint64
    Position int
    Siblings TestItems
    Name     string
}

// Leaf interface implementation for TestItem
// ...
// Leafs interface implementation for TestItems
// ...

func main() {
    flatItemsSlice := getTestItems()

    var parent = TestItem{}
    if err := mpath.InitTree(&parent, flatItemsSlice); err != nil {
        panic("error tree init")
    }
    
    fmt.Print(parent)
}

func getTestItems() *TestItems {
    return &TestItems{
        {ID: 1, Position: 0, Name: "item 1", Path: []uint64{1}},
        {ID: 2, Position: 0, Name: "item 2", Path: []uint64{1, 2}},
        {ID: 3, Position: 1, Name: "item 3", Path: []uint64{1, 3}},
        {ID: 4, Position: 0, Name: "item 4", Path: []uint64{1, 2, 4}},
        {ID: 5, Position: 1, Name: "item 5", Path: []uint64{1, 2, 5}},
        {ID: 6, Position: 0, Name: "item 6", Path: []uint64{1, 3, 6}},
    }
}

Tests

go test ./... -v -race
Owner
SpaceTab.io
Software matters
SpaceTab.io
Similar Resources

Go package that aids in binary analysis and exploitation

sploit Sploit is a Go package that aids in binary analysis and exploitation. The motivating factor behind the development of sploit is to be able to h

Jan 1, 2023

OCI Image Encryption Package

imgcrypt image encryption library and command line tool Project imgcrypt is a non-core subproject of containerd. The imgcrypt library provides API exe

Jan 5, 2023

A package manager written in Go which uses the LFS Symlink method.

pacsym A package manager powered by symlinks. How to use The package manager assumes that all software installed is installed with /usr/pkg/packagena

Dec 11, 2021

In-memory database package

Go FRM Module In-memory database package Usage Install module in your project: go get github.com/xpartacvs/go-frm Use the packages: package main impo

Dec 25, 2021

Package trn introduces a Range type with useful methods to perform complex operations over time ranges

Time Ranges Package trn introduces a Range type with useful methods to perform c

Aug 18, 2022

Package create provides a generic option pattern for creating new values of any type

create Package create provides a generic option pattern for creating new values

Dec 30, 2021

Io's package manager

Io's package manager

Amirani Io's package manager Contributors ✨ Thanks goes to these wonderful people (emoji key): an aspirin 💻 📖 🔧 🚧 This project follows the all-con

Feb 20, 2022

Dockpin - A tool for pinning Docker image and apt package versions

Dockpin Install dockpin with: go install github.com/Jille/dockpin@latest Dockpin

Dec 20, 2022

Package pinentry provides a minimal client to GnuPG's pinentry

go-pinentry-minimal Package pinentry provides a minimal client to GnuPG's pinentry, which only depends on Go's standard library. It is a fork of githu

Nov 20, 2022
Go library to wait for the detached/unmounted state of a path.

Unmountpoint Unmountpoint is Go library to wait for the detached/unmounted state of a path. DISCLAIMER: This project is under development and fully ex

Oct 19, 2022
GitHub Action to identify a path of changed files on monorepos, with regex and depth validation.

github-action-go GitHub Action to identify a path of changed files on monorepos, with regex and depth validation. Example use-case is execution path f

Mar 1, 2022
Tree style (files) explorer for p9p acme.

xplor, a tree-style (file) explorer for (plan9port) Acme screenshot, regular screenshot, monospaced Xplor is written for Acme, the Plan 9 text editing

Nov 25, 2021
Search for HCL(v2) using syntax tree

hclgrep Search for HCL(v2) using syntax tree. The idea is heavily inspired by ht

Dec 12, 2022
A package for running subprocesses in Go, similar to Python's subprocesses package.

Subprocesses Spawn subprocesses in Go. Sanitized mode package main import ( "log" "github.com/estebangarcia21/subprocess" ) func main() { s := s

Jul 28, 2022
Package bright-golang is a client for the Bright App energy monitoring API.

Go client library for the Bright API Package bright-golang is a client for the Bright App energy monitoring API. Not all the API endpoints are impleme

Jan 5, 2022
A Golang package for simplifying storing configuration in the OS-provided secret manager.

go-keyconfig A Golang package for simplifying storing configuration in the OS-provided secret manager. Operating System Support OS Secret Manager MacO

Jul 22, 2022
The missing package manager for golang binaries (its homebrew for "go install")

Bingo: The missing package manager for golang binaries (its homebrew for "go install") Do you love the simplicity of being able to download & compile

Oct 31, 2022
A golang package for comparing and working with k0s version numbers

version A go-language package for managing k0s version numbers. It is based on hashicorp/go-version but adds sorting and comparison capabilities for t

Feb 7, 2022