Skip to content

Commit

Permalink
[auto] Reflect the changes of main repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
nyabkun committed Jun 1, 2023
1 parent 97a304f commit f2c4e77
Show file tree
Hide file tree
Showing 68 changed files with 1,940 additions and 1,892 deletions.
23 changes: 0 additions & 23 deletions CallChainNodeHitCount.txt

This file was deleted.

168 changes: 103 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,143 @@
<!--- version = v2023-06-02 --->

# 🐕 qq-tree

**qq-tree** is a Kotlin library that can construct a tree structure.

- Just copy and paste 🟦 Single-File version [QTreeNode.kt](src-single/QTreeNode.kt) into your project.- Or you can use 🟩 Split-File Jar version. See [Maven Dependency Section](#-split-file-jar-version-maven-dependency).
- Feel free to fork or copy to your own codebase.
## How to use
- Just copy and paste Single-File version [QTreeNode.kt](src-single/QTreeNode.kt) into your project.
- Or you can use Jar version. See [Maven Dependency Section](#jar-version-maven-dependency).
- Feel free to fork or copy to your own codebase 😍

## Example

### output
<p align="center">
<img src="img/001-num-unicode.png" width="203" alt="001-num-unicode.png">
<img src="img/002-num-ascii.png" width="194" alt="002-num-ascii.png">
<img src="img/01-num-tree.png" width="200" alt="01-num-tree.png">
</p>
<p align="center">
<img src="img/003-walk-tree.png" width="443" alt="003-walk-tree.png">
<img src="img/02-tree-walk.png" width="459" alt="02-tree-walk.png">
</p>
<p align="center">
<img src="img/004-string-tree.png" width="250" alt="004-string-tree.png">
<img src="img/005-dir-tree.png" width="195" alt="005-dir-tree.png">
<img src="img/03-file-tree.png" width="375" alt="03-file-tree.png">
</p>

### code
### code example

Full Source [QTreeNodeExample.kt](src-example/QTreeNodeExample.kt)
Full Source : [QTreeNodeExample.kt](src-example/QTreeNodeExample.kt)

```kotlin
// First, you have to create the root node.
val root = QTreeNode(0)

val node1 = root add 1
val node2 = root add 2
val node3 = node2 add 3
val node4 = node2 add 4
val node5 = node4 add 5
val node6 = node4 add 6
val node7 = node2 add 7

val unicodeTree = root.tree(color = QShColor.GREEN, style = QTreeStyle.UNICODE)
fun intTree() {
// First, you have to create the root node.
val root = QTreeNode(0)

println(unicodeTree)
val node1 = root add 1
val node2 = root add 2
val node3 = node2 add 3
val node4 = node2 add 4
val node5 = node4 add 5
val node6 = node4 add 6
val node7 = node2 add 7

val asciiTree = root.tree(color = QShColor.BLUE, style = QTreeStyle.ASCII)
val unicodeTree = root.tree(color = QShColor.Green, style = QTreeStyle.UNICODE)

println(asciiTree)
println(unicodeTree)

println()
val asciiTree = root.tree(color = QShColor.Blue, style = QTreeStyle.ASCII)

val depthFirstResult = root.descendantsList(QSearchAlgo.DepthFirst).toString()
println(asciiTree)

println("DepthFirst : $depthFirstResult") // [0, 1, 2, 3, 4, 5, 6, 7]
println()

val breadthFirstResult = root.descendantsList(QSearchAlgo.BreadthFirst).toString()
val depthFirstResult = root.descendantsList(QSearchAlgo.DepthFirst).toString()

println("BreadthFirst : $breadthFirstResult") // [0, 1, 2, 3, 4, 7, 5, 6]
println("DepthFirst : $depthFirstResult") // [0, 1, 2, 3, 4, 5, 6, 7]

println()
val breadthFirstResult = root.descendantsList(QSearchAlgo.BreadthFirst).toString()

// node can store anything
val rootA = QTreeNode("A")
val nodeB = rootA add "B"
val nodeC = nodeB add "C"
val nodeD = nodeB add "D"
val nodeE = nodeD add "E"
val nodeF = nodeE add "F"
val nodeG = nodeC add "G"

val textTree = rootA.tree(color = QShColor.CYAN, style = QTreeStyle.UNICODE)
println("BreadthFirst : $breadthFirstResult") // [0, 1, 2, 3, 4, 7, 5, 6]
}

println(textTree)
fun textTree() {
// node can store anything
val rootA = QTreeNode("A")
val nodeB = rootA add "B"
val nodeC = nodeB add "C"
val nodeD = nodeB add "D"
val nodeE = nodeD add "E"
val nodeF = nodeE add "F"
val nodeG = nodeC add "G"

// You can implement QLazyNode for more complicated situations.
class QFileNode(override val value: Path) : QLazyTreeNode<Path> {
override fun hasChildNodesToFill(): Boolean {
return value.isDirectory()
}
val textTree = rootA.tree(color = QShColor.Cyan, style = QTreeStyle.UNICODE)

override fun fillChildNodes(): List<QFileNode> = Files.walk(value, 1).filter {
it != value
}.map {
QFileNode(it)
}.toList()
println(textTree)
}

override fun toTreeNodeString(): String {
return value.name
fun fileTree() {
// You can implement QLazyNode for more complicated situations.
class QFileNode(override val value: Path) : QLazyTreeNode<Path> {
override fun hasChildNodesToFill(): Boolean {
return value.isDirectory()
}

override fun fillChildNodes(): List<QFileNode> {
return Files.walk(value, 1).asSequence().filter {
it != value
}.sortedBy {
it.name
}.sortedBy {
!it.isDirectory()
}.map {
QFileNode(it)
}.toList()
}

override fun toTreeNodeString(): String {
return if (value.isDirectory()) "📁" + value.name else value.name
}
}
}

val rootDir = Paths.get("rsc-test/root-dir").toAbsolutePath()
val rootDir = Paths.get("src-split").toAbsolutePath()

val fileTree = QFileNode(rootDir).fillTree(maxDepth = 2).tree()
val fileTree = QFileNode(rootDir).fillTree(maxDepth = 3).tree()

println(fileTree)
println(fileTree)
}
```

Please see [QTreeNodeTest.kt](src-test-split/nyab/util/QTreeNodeTest.kt) for more code examples.
Single-File version [src-test-single/QTreeNodeTest.kt](src-test-single/QTreeNodeTest.kt) is a self-contained source code that includes a runnable main function.
You can easily copy and paste it into your codebase.

## 🟦 Single-File version Dependency

If you copy & paste [QTreeNode.kt](src-single/QTreeNode.kt).

Refer to [build.gradle.kts](build.gradle.kts) to directly check project settings.
## Public API

- [`N.fillTree()`](src-split/nyab/util/QTreeNode.kt#L71-L110) *extension function*
- [`N.root()`](src-split/nyab/util/QTreeNode.kt#L112-L122) *extension function*
- [`N.isRoot()`](src-split/nyab/util/QTreeNode.kt#L124-L128) *extension function*
- [`N.hasCycle()`](src-split/nyab/util/QTreeNode.kt#L130-L149) *extension function*
- [`N.depth()`](src-split/nyab/util/QTreeNode.kt#L191-L207) *extension function*
- [`N.tree()`](src-split/nyab/util/QTreeNode.kt#L222-L269) *extension function*
- [`N.descendants()`](src-split/nyab/util/QTreeNode.kt#L271-L284) *extension function*
- [`N.add()`](src-split/nyab/util/QTreeNode.kt#L385-L393) *extension function*
- [`N.add()`](src-split/nyab/util/QTreeNode.kt#L395-L407) *extension function*
- [`N.add()`](src-split/nyab/util/QTreeNode.kt#L409-L415) *extension function*
- [`N.newNode()`](src-split/nyab/util/QTreeNode.kt#L417-L425) *extension function*
- [`N.ancestors()`](src-split/nyab/util/QTreeNode.kt#L427-L449) *extension function*
- [`N.descendantsList()`](src-split/nyab/util/QTreeNode.kt#L451-L458) *extension function*
- [`N.ancestorsList()`](src-split/nyab/util/QTreeNode.kt#L460-L466) *extension function*
- [`N.isLeaf`](src-split/nyab/util/QTreeNode.kt#L151-L156) *extension property*
- [`N.parent`](src-split/nyab/util/QTreeNode.kt#L158-L174) *extension property*
- [`N.children`](src-split/nyab/util/QTreeNode.kt#L176-L189) *extension property*
- [`QTreeNode`](src-split/nyab/util/QTreeNode.kt#L22-L31) *class*
- [`QLazyTreeNode`](src-split/nyab/util/QTreeNode.kt#L33-L54) *interface*
- [`QTreeNodeI`](src-split/nyab/util/QTreeNode.kt#L56-L69) *interface*
- [`QTreeStyle`](src-split/nyab/util/QTreeNode.kt#L209-L220) *enum class*
- [`QSearchAlgo`](src-split/nyab/util/QTreeNode.kt#L468-L476) *enum class*

## Single-File version Dependency

If you copy & paste [QTreeNode.kt](src-single/QTreeNode.kt),
fefer to [build.gradle.kts](build.gradle.kts) to directly check project settings.



Expand All @@ -112,9 +148,10 @@ dependencies {
}
```

## 🟩 Split-File Jar version Maven Dependency
## Jar version Maven Dependency

If you prefer a jar library. Add [jitpack.io](https://jitpack.io/#nyabkun/qq-tree) repository to the build script.
If you prefer a jar library,
you can use [jitpack.io](https://jitpack.io/#nyabkun/qq-tree) repository.

### build.gradle ( Groovy )
```groovy
Expand Down Expand Up @@ -162,7 +199,8 @@ dependencies {

## How did I create this library

- This library was created using [qq-compact-lib](https://github.com/nyabkun/qq-compact-lib) to generates compact, self-contained libraries.
- This library was created using [qq-compact-lib](https://github.com/nyabkun/qq-compact-lib) to generates a compact, self-contained library.
- **qq-compact-lib** is a Kotlin library that can extract code elements from your codebase and make a compact library.
- It utilizes [PSI](https://plugins.jetbrains.com/docs/intellij/psi.html) to resolve function calls and class references.
- The original repository is currently being organized, and I'm gradually extracting and publishing smaller libraries.

5 changes: 3 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
v2023-05-28
f5b4d712c22124fd15407d08997388b76e203043bd70d311e0d99743b371686862e5dc3710e95643d6996905b36afa739d1a85608de21f0974de692eb1475d3b
v2023-06-02
9f574957f68e0c5fa892cca1a02c6780848e9703f7469edf640b72eae033539c1a1d8f3eaf980b909a7c78afbd552713b64c4474dbb5def02299498427a080fe
build/libs/qq-tree-v2023-06-02.jar;build/libs/qq-tree-v2023-06-02-sources.jar
60 changes: 30 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ plugins {

}

group = "com.nyabkun.qol"
group = "com.github.nyabkun"

version = "v2023-05-28"
version = "v2023-06-02"

repositories {
mavenCentral()
Expand All @@ -45,37 +45,37 @@ java {


sourceSets.main {
java.srcDirs("src-split")
java.srcDirs("src-split")

resources.srcDirs("rsc")
}
resources.srcDirs("rsc")
}

sourceSets.test {
java.srcDirs("src-test-split")
sourceSets.test {
java.srcDirs("src-test-split")

resources.srcDirs("rsc-test")
}
sourceSets.register("example") {
java.srcDirs("src-example")
val jarFile = "$buildDir/libs/$qMavenArtifactId-$version.jar"
compileClasspath += files(jarFile)
runtimeClasspath += files(jarFile)
resources.srcDirs("rsc")
}
tasks.getByName("compileExampleKotlin").dependsOn("jar")
val exampleImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
}
val exampleRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}
sourceSets.register("single") {
resources.srcDirs("rsc-test")
}

sourceSets.register("example") {
java.srcDirs("src-example")
val jarFile = "$buildDir/libs/$qMavenArtifactId-$version.jar"
compileClasspath += files(jarFile)
runtimeClasspath += files(jarFile)

resources.srcDirs("rsc")
}

tasks.getByName("compileExampleKotlin").dependsOn("jar")

val exampleImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
}

val exampleRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}

sourceSets.register("single") {
java.srcDirs("src-single")
}

Expand Down
Binary file removed img/001-num-unicode.png
Binary file not shown.
Binary file removed img/002-num-ascii.png
Binary file not shown.
Binary file removed img/003-walk-tree.png
Binary file not shown.
Binary file removed img/004-string-tree.png
Binary file not shown.
Binary file removed img/005-dir-tree.png
Binary file not shown.
Binary file added img/01-num-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/02-tree-walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/03-file-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added rsc-test/root/Adir/A.txt
Empty file.
Empty file added rsc-test/root/Adir/Bdir/D.txt
Empty file.
Empty file added rsc-test/root/Adir/C.txt
Empty file.
Empty file added rsc-test/root/B.txt
Empty file.
Loading

0 comments on commit f2c4e77

Please sign in to comment.