Skip to content

Commit

Permalink
Merge test and main (#2)
Browse files Browse the repository at this point in the history
* Adding simple gitignore file template

* Adding gradle project files

* Adding search tree library file structure at project

* Update nodes classes and interfaces with adding properties and update its methods

* Update search-tree interface and simple init by abstract binary search tree properties as root and tree size

* Update abstract node class to calling update data method for balanced tree's nodes

* Adding simple ReadMe file with  description about library by path ./lib/ReadMe.md

* Adding LICENSE file with MIT-License description

* Update LICENSE file with MIT-License description by fix names of the rights holders

* feat(AVLTree): implement balance functions

* feat(AVLTree): implement insert

* feat(AVLTree): implement remove and removeWithDefault

* refactor(AVLTreeNode): simplify updatingHeight and remove updateNodeData

* feat: add general methods and rename file RedBlackTree

* feat(Refactoring): The implementation of the removeWithDefault(K) method is placed in an abstract class. Clearing some todos from labels. Corrected the AVLTree.kt file by adding the missing maxDescendantForAVL(AVLTreeNode<K, V>) AVLTree method to the class. Added TODO marks in the BSTree file defining the implementation of the insert & remove methods

* feat(Addding iterators):

Add subdirrectory with files of intreface SearchTreeIterator and enum of orders to iterate on search trees and class of BinarySearchTreeIterator to iterate on BST and other implementations of it

* feat(Adding iterators)

* feat(Adding insert operation at RBTree)

Add implementation of insert method of SearchTree at class RBTree and add new method at SearchTree interface with name insertIfAbsent

* refactor: rewrite combine remove and insert for AVLTree and BSTree (not build)

BREAKING CHANGE: implement methods for an AbstractBSTree, refactor AbstractBSTree, BSTree, SearchTree, SearchTreeNode, AbstractBSTreeNode, BSTreeNode. Add the pattern of ignoring to .gitignore

* refactor(AVLTree & AVLTreeNode): combine code with AbstractBSTree. Add enter to .gitignore

* refactor: update RBTree & RBTreeNode by combining the insert method with AbstractBSTree. Add implementation of the remove method at RBTree. Remove unnecessary interface of SearchTreeIterator. Update BinarySearchTreeIterator by implementing Iterator interface. Update ReadMe by adding info about finished trees

* feat: Update lib/ReadMe.md by adding description of library and some examples of using it

* feat: add simple root ReadMe for project with simple info upbout it

* fix: invalid header which do not display information about the project on the github of root readme by removing it

* feat: Adding doc-string for some source files.

Docs integrated on IterationOrders.kt, BinarySearchTreeIterator.kt, RBTree.kt, RBTreeNode.kt and Utils.kt

* docs(AVLTree & AVLTreeNode): add doc-strings

* style: rename one method to 'contains' and rename the library to 'TreeTripper'

* feat: add 'get' and 'set' methods to interact with trees as with a map

* docs: add doc-strings for the classes and interfaces: SearchTree, SearchTreeNode, AbstractBSTree, AbstractBSTreeNode, BSTree, BSTreeNode

* refactor: add more information to the ReadMe file withsome links to docs and more info about implementation about red-black tree

* refactor: update info at root ReadMe file by updating roadmap and authors informations

* test: add simple tests case for RBTree such as initializing tree, checking methods of node colors, update access params of method and properties from private to protected, add method to comparing by equals for nodes

* fix: remove invalid assertion method for RBTreeTestAssistant which used for check results of left rotation for nodes

* refactor: replace equals nodes methods to assertions utils file(AssertionUtils.kt)

* test: add tests for utility methods to work with nodes

* test: add tests for red-black tree node to check valid initialize and toString methods

* refactor: update method source to template view: 'test%(test-name)Cases'

* refactor: update test methods name to template view: 'test%(test-cause)' at RBTreeTest.kt file

* test: add tests for private left and right node rotations methods

* test: add test for private method to flip color of node and its childs colors

* test: add tests for private methods of creation new tree node, updating root and add empty test for balance tree method

* test(AVLTreeNode): add constructor for node, add tests for updateHeight

* test(AVLTree): update access params of method from private to protected, add tests for balanceFactor, rotateLeft, rotateRight

* test: update test for balance tree method by adding cases to test it

* refactor: remove redundant information at file RBTreeTest.kt during object initialization, and remove unnecessary tree creation in the initialization test, remove commented-out code in file RBTreeNodeTest.kt

* test(AVLTree): add tests for balance, add test for balanceFactor, changed how checkBalanceFactor works, refactor tests

* test: add tests for insert methods such as insert 1 element, insert double unequals values by 1 key, insert sorted elements insert reversed of sorted elements and unsorted elements

* refactor: update initialize test by adding assertion 'is tree with root equals null is RBTree'

* refactor: remove output printing log information of insert tests

* refactor: update private insert of test to test public tree method 'set' together with 'insert'

* test(AVLTree): add tests for createNode, balanceTree

* test(AVLTreeNode): add test for class field

* test(BSTree): BSTreeTest and BSTreeTestAssistant classes are created. BSTree class is opened for BSTreeTestAssistant inheritance. Add tests for the check tree initialization, node creation and insert methods

* test: add autotests that build the project and run tests with 'jacoco'. Add 'jacoco' in build.gradle.kts. Add '@DisplayName' for correct output of the test name to the console

* docs: update ReadMe, delete ReadMe from lib/

* docs: update links in ReadMe

* refactor: rename several methods according to their invariant. Renumber examples in ReadMe

* test: add tests of basic methods for AbstractBSTree

* docs: fix the typo in 'removeOrDefault' method

* test(BSTree): add tests for 'updateRoot' and 'balanceTree' methods

---------

Co-authored-by: IliaSuponeff <[email protected]>
Co-authored-by: Maxim Rodionov <[email protected]>
Co-authored-by: Friend-zva <[email protected]>
  • Loading branch information
4 people authored Mar 31, 2024
1 parent 4bff01b commit 7975b78
Show file tree
Hide file tree
Showing 36 changed files with 3,441 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

19 changes: 19 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build and test

on:
workflow_dispatch:

push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build source code and run test with jacoco
run: ./gradlew :test
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Gradle console-app generated template
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
*/build/*

### VSCode Template
.vscode/

### IntelliJ IDEA Template
.idea/
*.iml

### Apple MacOS folder attributes
*.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Ilia Suponev, Rodionov Maxim, Vladimir Zaikin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
261 changes: 261 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
[//]: # (Project readme template from https://github.com/othneildrew/Best-README-Template/)
<a name="readme-top"></a>

[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)


<h1 align="center">TreeTripper</h1>

## Description

Library `TreeTripper`: provides implementations of the following binary search tree data structures:
- [x] [`Binary Search Tree`](lib/src/main/kotlin/tree_tripper/binary_trees/BSTree.kt), see more [information](https://en.wikipedia.org/wiki/Binary_search_tree)
- [x] [`AVL tree`](lib/src/main/kotlin/tree_tripper/binary_trees/AVLTree.kt), see more [information](https://en.wikipedia.org/wiki/AVL_tree)
- [x] [`Red-black tree`](lib/src/main/kotlin/tree_tripper/binary_trees/RBTree.kt),
see more [information](https://en.wikipedia.org/wiki/Left-leaning_red%E2%80%93black_tree)

> [!IMPORTANT]
> The red-black tree is implemented based on the algorithm
> of left-linear red-black trees described by Robert Sedgewick
> on his [website](https://sedgewick.io/) and [presentation](https://sedgewick.io/wp-content/uploads/2022/03/2008-09LLRB.pdf) about it
The library supports the extension both internally (future library updates) and externally (implemented by the user).

## Getting started
To run building library execute command:
```bash
./gradlew build
```

## Using library

### Basic operations
+ `insert`, see [docs](lib/src/main/kotlin/tree_tripper/SearchTree.kt#L17)
+ `search`, see [docs](lib/src/main/kotlin/tree_tripper/SearchTree.kt#L50)
+ `remove`, see [docs](lib/src/main/kotlin/tree_tripper/SearchTree.kt#L36)

### Examples

##### Example 1 (importing)
```kotlin
import tree_tripper.binary_trees.BSTree
import tree_tripper.binary_trees.AVLTree
import tree_tripper.binary_trees.RBTree


val simpleTree = BSTree<String, Int>() // initialization of empty simple binary search tree
val avlTree = AVLTree<Int, StringBuilder>() // initialization of empty AVL tree
val rbTree = RBTree<String, LinkedHashSet<Long>>() // initialization of empty Red-Black tree
```

##### Example 2 (inserting)
Code:
```kotlin
import tree_tripper.binary_trees.BSTree

fun main() {
val tree = BSTree<Int, Int>()

tree.insert(key = 1, value = 1)
tree.insert(key = 2, value = 2)
tree.insert(key = 3, value = 3)
tree.insert(key = 4, value = 4)
tree.insert(key = 5, value = 5)

println(tree)
}
```
Output:
```text
BSTree(1: 1, 2: 2, 3: 3, 4: 4, 5: 5, )
```

##### Example 3 (searching)
Code:
```kotlin
import tree_tripper.binary_trees.BSTree

fun main() {
val tree = BSTree<Int, Int>()
/*
...
inserting from `example 2`
...
*/

/* Existing element in tree */
println(tree.search(key = 1))
println(tree.search(key = 3))
println(tree.search(key = 5))

/* Unexciting element in tree */
println(tree.search(key = -2))
println(tree.search(key = 7))

/* Alternative search method */
println(tree[2])
println(tree[0])
}
```
Output:
```text
1
3
5
null
null
2
null
```

##### Example 4 (removing)
Code:
```kotlin
import tree_tripper.binary_trees.BSTree

fun main() {
val tree = BSTree<Int, Any>()
/*
...
inserting from `example 2`
...
*/

/* Existing element in tree */
println(tree.remove(key = 1))
println(tree.remove(key = 3))
println(tree.remove(key = 5))

/* Unexciting element in tree */
println(tree.remove(key = -2))
println(tree.removeOrDefault(key = 7, "Element not found"))

println(tree)
}
```
Output:
```text
1
3
5
null
Element not found
BSTree(2: 2, 4: 4, )
```

##### Example 5 (tree-like printing)
Code:
```kotlin
import tree_tripper.binary_trees.BSTree
import tree_tripper.binary_trees.AVLTree
import tree_tripper.binary_trees.RBTree

fun main() {
val simpleTree = BSTree<Int, Int>()
val avlTree = AVLTree<Int, Int>()
val rbTree = RBTree<Int, Int>()
/*
...
inserting similar to `example 2` for each tree
...
*/

println("${simpleTree.toStringWithTreeView()}\n")
println("${avlTree.toStringWithTreeView()}\n")
println("${rbTree.toStringWithTreeView()}\n")
}
```
Output:
```text
BSTree(
(5, 5)
(4, 4)
(3, 3)
(2, 2)
(1, 1)
)
AVLTree(
(5, 5)
(4, 4)
(3, 3)
(2, 2)
(1, 1)
)
RBTree(
(5, 5) - BLACK
(4, 4) - BLACK
(3, 3) - BLACK
(2, 2) - RED
(1, 1) - BLACK
)
```

##### Example 6 (iterators)
Code:
```kotlin
import tree_tripper.binary_trees.AVLTree

fun main() {
val tree = AVLTree<Int, Int>()
/*
...
inserting from `example 2`
...
*/

println("WIDTH ORDER:")
tree.forEach(IterationOrders.WIDTH_ORDER) {
println(it)
}
println()
println("INCREASING ORDER:")
tree.forEach(IterationOrders.INCREASING_ORDER) {
println(it)
}
println()
println("DECREASING ORDER:")
tree.forEach(IterationOrders.DECREASING_ORDER) {
println(it)
}
}
```
Output:
```text
WIDTH ORDER:
(2, 2)
(1, 1)
(4, 4)
(3, 3)
(5, 5)
INCREASING ORDER:
(1, 1)
(2, 2)
(3, 3)
(4, 4)
(5, 5)
DECREASING ORDER:
(5, 5)
(4, 4)
(3, 3)
(2, 2)
(1, 1)
```

## Documentation
See more [_**documentation**_](lib/src/main/kotlin/tree_tripper/SearchTree.kt) of library `TreeTripper` to learn more about it.

## Authors

- [@IliaSuponeff](https://github.com/IliaSuponeff)
- [@RodionovMaxim05](https://github.com/RodionovMaxim05)
- [@Friend-zva](https://github.com/Friend-zva), sometimes in commits his name is _**Vladimir Zaikin**_

## License

Distributed under the [MIT License](https://choosealicense.com/licenses/mit/). See [`LICENSE`](LICENSE) for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

org.gradle.parallel=true
org.gradle.caching=true

13 changes: 13 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
commons-math3 = "3.6.1"
guava = "32.1.3-jre"

[libraries]
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }

[plugins]
jvm = { id = "org.jetbrains.kotlin.jvm", version = "1.9.20" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 7975b78

Please sign in to comment.