Skip to content

spbu-coding-2024/trees-trees-team-5

Repository files navigation

Monke pic

MONKE

Kotlin library providing simple interface to work with data for some types of binary trees


🌲 Supported Trees

  • Binary Search Tree
  • AVL Tree
  • Red-Black Tree
  • Two-Three Tree

🛠️ Quick Start

import monke.trees.BSTree

fun main() {

    val bst = BSTree<Int, String>()

    bst.insert(1, "Example value for search method")

    println(bst.search(1)) // Example value for search method
}

💡 Features

  • Arithmetic operations - add and subtract interface for two trees to insert or remove all nodes of one tree into/from another one
  • Get operator - retrieving values using the get operator with a key

📃 Example

Get value by key

import monke.trees.BSTree

fun main() {

    val bst = BSTree<Int, String>()

    bst.insert(1, "Example value for get method")

    println(bst[1]) // Example value for get method
}

🧮 Arithmetic

Plus

import monke.trees.BSTree

fun main() {
    val tree1 = BSTree<Int, String>()
    val tree2 = BSTree<Int, String>()
    tree1.insert(1, "value from first tree")
    tree2.insert(2, "value from second tree")

    val tree3 = tree1.copy() + tree2
    tree3.insert(-1, "value from third tree")
    for (i in tree3) {
        println(i)
    }
    /*
    (1, value from first tree)
    (-1, value from third tree)
    (2, value from second tree)
    */
}

Important

Inserting a node with an existing key results in an error. Ensure keys are unique before inserting.

Minus

import monke.trees.BSTree

fun main() {
    var tree1 = BSTree<Int, String>()
    tree1.insert(1, "value 1")
    tree1.insert(2, "value 2")
    tree1.insert(3, "value 3")
    val tree2 = tree1.copy()

    tree1.insert(4, "value 4")

    tree1 -= tree2

    for (i in tree1) {
        println(i)
    }
/*
(4, value 4)
*/

Important

As in addition, try to delete a key that does not exist in the tree throws an error.

📖 Documentation

To generate documentation, run:
./gradlew dokkaHtml
from the project root.


👨‍💻 Authors

🪪 License

This project is licensed under the MIT License.

About

trees-trees-team-5 created by GitHub Classroom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages