mirror of
				https://github.com/AdrianKuta/Tree-Data-Structure.git
				synced 2025-10-31 00:43:40 +01:00 
			
		
		
		
	Compare commits
	
		
			9 Commits
		
	
	
		
			develop
			...
			60c50f078d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 60c50f078d | ||
|   | 54f5074483 | ||
|   | 772eeb0465 | ||
|   | 456f889b9c | ||
|   | c3a4ca5925 | ||
|   | 06dc507590 | ||
|   | 5eaf027dba | ||
|   | 04c3728fcd | ||
|   | d34050e9af | 
							
								
								
									
										11
									
								
								.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # To get started with Dependabot version updates, you'll need to specify which | ||||
| # package ecosystems to update and where the package manifests are located. | ||||
| # Please see the documentation for all configuration options: | ||||
| # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||||
|  | ||||
| version: 2 | ||||
| updates: | ||||
|   - package-ecosystem: "" # See documentation for possible values | ||||
|     directory: "/" # Location of package manifests | ||||
|     schedule: | ||||
|       interval: "weekly" | ||||
							
								
								
									
										20
									
								
								.github/workflows/publishRelease.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										20
									
								
								.github/workflows/publishRelease.yml
									
									
									
									
										vendored
									
									
								
							| @@ -19,20 +19,18 @@ jobs: | ||||
|     steps: | ||||
|       - name: Check out code | ||||
|         uses: actions/checkout@v2 | ||||
|       - name: Set up JDK 11 | ||||
|         uses: actions/setup-java@v2 | ||||
|       - name: Set up JDK 21 | ||||
|         uses: actions/setup-java@v4 | ||||
|         with: | ||||
|           distribution: adopt | ||||
|           java-version: 11 | ||||
|           distribution: temurin | ||||
|           java-version: '21' | ||||
|  | ||||
|         # Runs upload, and then closes & releases the repository | ||||
|       - name: Publish to MavenCentral | ||||
|         run: ./gradlew publish --max-workers 1 | ||||
|         run: ./gradlew publishToMavenCentral | ||||
|         env: | ||||
|           OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||||
|           OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | ||||
|           SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} | ||||
|           SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | ||||
|           SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | ||||
|           SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} | ||||
|           ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | ||||
|           ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | ||||
|           ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} | ||||
|           ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} | ||||
|           SNAPSHOT: false | ||||
							
								
								
									
										35
									
								
								.github/workflows/publishSnapshot.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								.github/workflows/publishSnapshot.yml
									
									
									
									
										vendored
									
									
								
							| @@ -1,35 +0,0 @@ | ||||
| name: Publish Snapshot | ||||
|  | ||||
| on: | ||||
|   push: | ||||
|     branches: [master, '14-**'] | ||||
|  | ||||
| jobs: | ||||
|   test: | ||||
|     uses: ./.github/workflows/test.yml | ||||
|     secrets: inherit | ||||
|  | ||||
|   publish: | ||||
|     needs: test | ||||
|     name: Publish Snapshot | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - name: Check out code | ||||
|         uses: actions/checkout@v2 | ||||
|       - name: Set up JDK 11 | ||||
|         uses: actions/setup-java@v2 | ||||
|         with: | ||||
|           distribution: adopt | ||||
|           java-version: 11 | ||||
|  | ||||
|         # Runs upload, and then closes & releases the repository | ||||
|       - name: Publish to snapshot to Sonatype | ||||
|         run: ./gradlew publish --max-workers 1 | ||||
|         env: | ||||
|           OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||||
|           OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | ||||
|           SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} | ||||
|           SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | ||||
|           SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | ||||
|           SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} | ||||
|           SNAPSHOT: true | ||||
							
								
								
									
										10
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							| @@ -12,12 +12,12 @@ jobs: | ||||
|     steps: | ||||
|       - name: Check out code | ||||
|         uses: actions/checkout@v2 | ||||
|       - name: Set up JDK 11 | ||||
|         uses: actions/setup-java@v2 | ||||
|       - name: Set up JDK 21 | ||||
|         uses: actions/setup-java@v4 | ||||
|         with: | ||||
|           distribution: adopt | ||||
|           java-version: 11 | ||||
|           distribution: temurin | ||||
|           java-version: '21' | ||||
|  | ||||
|         # Builds the release artifacts of the library | ||||
|       - name: Test | ||||
|         run: ./gradlew test | ||||
|         run: ./gradlew cleanJvmTest jvmTest | ||||
							
								
								
									
										6
									
								
								.idea/AndroidProjectSystem.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/AndroidProjectSystem.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="AndroidProjectSystem"> | ||||
|     <option name="providerId" value="com.android.tools.idea.GradleProjectSystem" /> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										35
									
								
								.idea/codeStyles/Project.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										35
									
								
								.idea/codeStyles/Project.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,5 +1,40 @@ | ||||
| <component name="ProjectCodeStyleConfiguration"> | ||||
|   <code_scheme name="Project" version="173"> | ||||
|     <JavaCodeStyleSettings> | ||||
|       <option name="IMPORT_LAYOUT_TABLE"> | ||||
|         <value> | ||||
|           <package name="" withSubpackages="true" static="false" module="true" /> | ||||
|           <package name="android" withSubpackages="true" static="true" /> | ||||
|           <package name="androidx" withSubpackages="true" static="true" /> | ||||
|           <package name="com" withSubpackages="true" static="true" /> | ||||
|           <package name="junit" withSubpackages="true" static="true" /> | ||||
|           <package name="net" withSubpackages="true" static="true" /> | ||||
|           <package name="org" withSubpackages="true" static="true" /> | ||||
|           <package name="java" withSubpackages="true" static="true" /> | ||||
|           <package name="javax" withSubpackages="true" static="true" /> | ||||
|           <package name="" withSubpackages="true" static="true" /> | ||||
|           <emptyLine /> | ||||
|           <package name="android" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="androidx" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="com" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="junit" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="net" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="org" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="java" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="javax" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|           <package name="" withSubpackages="true" static="false" /> | ||||
|           <emptyLine /> | ||||
|         </value> | ||||
|       </option> | ||||
|     </JavaCodeStyleSettings> | ||||
|     <JetCodeStyleSettings> | ||||
|       <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> | ||||
|     </JetCodeStyleSettings> | ||||
|   | ||||
							
								
								
									
										3
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							| @@ -4,8 +4,9 @@ | ||||
|   <component name="GradleSettings"> | ||||
|     <option name="linkedExternalProjectsSettings"> | ||||
|       <GradleProjectSettings> | ||||
|         <option name="distributionType" value="WRAPPED" /> | ||||
|         <option name="testRunner" value="CHOOSE_PER_TEST" /> | ||||
|         <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||||
|         <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> | ||||
|         <option name="modules"> | ||||
|           <set> | ||||
|             <option value="$PROJECT_DIR$" /> | ||||
|   | ||||
							
								
								
									
										9
									
								
								.idea/kotlinScripting.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								.idea/kotlinScripting.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,9 +0,0 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="KotlinScriptingSettings"> | ||||
|     <scriptDefinition className="org.jetbrains.kotlin.scripting.resolve.KotlinScriptDefinitionFromAnnotatedTemplate" definitionName="KotlinBuildScript"> | ||||
|       <order>2147483647</order> | ||||
|       <autoReloadConfigurations>true</autoReloadConfigurations> | ||||
|     </scriptDefinition> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,7 +1,7 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="ExternalStorageConfigurationManager" enabled="true" /> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK"> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK"> | ||||
|     <output url="file://$PROJECT_DIR$/out" /> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										17
									
								
								.idea/runConfigurations.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.idea/runConfigurations.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="RunConfigurationProducerService"> | ||||
|     <option name="ignoredProducers"> | ||||
|       <set> | ||||
|         <option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" /> | ||||
|         <option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" /> | ||||
|         <option value="com.intellij.execution.junit.PatternConfigurationProducer" /> | ||||
|         <option value="com.intellij.execution.junit.TestInClassConfigurationProducer" /> | ||||
|         <option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" /> | ||||
|         <option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" /> | ||||
|         <option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" /> | ||||
|         <option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" /> | ||||
|       </set> | ||||
|     </option> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										6
									
								
								.idea/studiobot.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/studiobot.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="StudioBotProjectSettings"> | ||||
|     <option name="shareContext" value="OptedIn" /> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										2
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="VcsDirectoryMappings"> | ||||
|     <mapping directory="$PROJECT_DIR$" vcs="Git" /> | ||||
|     <mapping directory="" vcs="Git" /> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										102
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										102
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,9 +1,40 @@ | ||||
| # Tree (Data Structure) | ||||
| [](https://mvnrepository.com/artifact/com.github.adriankuta/tree-structure) | ||||
| [](https://github.com/AdrianKuta/Tree-Data-Structure/blob/master/LICENSE) | ||||
| [](https://github.com/AdrianKuta/Tree-Data-Structure/actions/workflows/publish.yml) | ||||
| [](https://github.com/AdrianKuta/Tree-Data-Structure/actions/workflows/publishRelease.yml) | ||||
|  | ||||
| Simple implementation to store object in tree structure. | ||||
| Lightweight Kotlin Multiplatform tree data structure for Kotlin and Java. Includes a small DSL, multiple traversal iterators, and pretty-print support. | ||||
|  | ||||
| - Kotlin Multiplatform (JVM, JS, iOS, and Native host) | ||||
| - Pre-order, Post-order, and Level-order iteration | ||||
| - Simple DSL: tree { child(...) } | ||||
| - Utilities: nodeCount(), height(), depth(), path(), prettyString(), clear(), removeChild() | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| Gradle (Kotlin DSL): | ||||
| ```kotlin | ||||
| // commonMain for KMP projects, or any sourceSet/module where you need it | ||||
| dependencies { | ||||
|     implementation("com.github.adriankuta:tree-structure:3.1.1") // see badge above for the latest version | ||||
| } | ||||
| ``` | ||||
|  | ||||
| Gradle (Groovy): | ||||
| ```groovy | ||||
| dependencies { | ||||
|     implementation "com.github.adriankuta:tree-structure:3.1.1" // see badge above for the latest | ||||
| } | ||||
| ``` | ||||
|  | ||||
| Maven: | ||||
| ```xml | ||||
| <dependency> | ||||
|   <groupId>com.github.adriankuta</groupId> | ||||
|   <artifactId>tree-structure</artifactId> | ||||
|   <version>3.1.1</version> | ||||
| </dependency> | ||||
| ``` | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| @@ -25,14 +56,10 @@ europe.addChild(france) | ||||
| println(root.prettyString()) | ||||
| ``` | ||||
|  | ||||
| **Pretty Kotlin** | ||||
|  | ||||
| **Pretty Kotlin (DSL)** | ||||
| ```kotlin | ||||
| val root = | ||||
|     tree("World") { | ||||
|         child("North America") { | ||||
|             child("USA") | ||||
|         } | ||||
| val root = tree("World") { | ||||
|     child("North America") { child("USA") } | ||||
|     child("Europe") { | ||||
|         child("Poland") | ||||
|         child("Germany") | ||||
| @@ -58,8 +85,7 @@ europe.addChild(france); | ||||
| System.out.println(root.prettyString()); | ||||
| ``` | ||||
|  | ||||
| *Output:* | ||||
|  | ||||
| Output: | ||||
| ``` | ||||
| World | ||||
| ├── North America | ||||
| @@ -69,10 +95,58 @@ World | ||||
|     └── France | ||||
| ``` | ||||
|  | ||||
| ### Traversal and utilities | ||||
| ```kotlin | ||||
| val root = TreeNode("root") | ||||
| // ... build your tree | ||||
|  | ||||
| ## Download | ||||
| // Choose iteration order (default is PreOrder) | ||||
| root.treeIterator = TreeNodeIterators.PostOrder | ||||
| for (node in root) println(node.value) | ||||
|  | ||||
|     implementation "com.github.adriankuta:tree-structure:$latest_versions" | ||||
| // Utilities | ||||
| root.nodeCount()   // number of descendants | ||||
| root.height()      // longest path to a leaf (in edges) | ||||
| root.depth()       // distance from current node to the root | ||||
| val path = root.path(root.children.first()) // nodes from descendant up to root | ||||
|  | ||||
| // Mutations | ||||
| val child = root.children.first() | ||||
| root.removeChild(child) | ||||
| root.clear()       // remove entire subtree | ||||
| ``` | ||||
|  | ||||
| ## Publishing to Maven Central (central.sonatype.com) | ||||
|  | ||||
| This project is configured to publish artifacts to Maven Central via the Sonatype Central Portal. | ||||
|  | ||||
| There are two supported ways to publish: | ||||
|  | ||||
| 1) Via GitHub Actions (recommended) | ||||
| - Create a GitHub Release (tag) in this repository. When a release is published, the workflow .github/workflows/publishRelease.yml runs automatically. | ||||
| - The workflow uses the Gradle task publishToMavenCentral to upload artifacts through the Central Portal. | ||||
| - Make sure these repository secrets are configured in GitHub: | ||||
|   - MAVEN_CENTRAL_USERNAME — Your Sonatype Central username (not email). | ||||
|   - MAVEN_CENTRAL_PASSWORD — Your Sonatype Central password or a token from central.sonatype.com. | ||||
|   - SIGNING_KEY — ASCII‑armored GPG private key (exported, single line; for in‑memory signing). | ||||
|   - SIGNING_PASSWORD — Passphrase for the key above. | ||||
| - The workflow uses JDK 21 and publishes the version defined in build.gradle.kts. | ||||
|  | ||||
| 2) Locally via Gradle | ||||
| - Ensure you have a Sonatype Central account and that the groupId com.github.adriankuta is verified in central.sonatype.com (Namespace Rules → Verify). | ||||
| - Export the same credentials/signing values as environment variables or pass them as Gradle properties: | ||||
|   - ORG_GRADLE_PROJECT_mavenCentralUsername | ||||
|   - ORG_GRADLE_PROJECT_mavenCentralPassword | ||||
|   - ORG_GRADLE_PROJECT_signingInMemoryKey | ||||
|   - ORG_GRADLE_PROJECT_signingInMemoryKeyPassword | ||||
| - Then run: | ||||
|   - ./gradlew publishToMavenCentral | ||||
| - For snapshot publishing, set -Psnapshot=true (the version is derived from PUBLISH_VERSION with -SNAPSHOT). | ||||
|  | ||||
| Notes | ||||
| - Publishing is powered by the com.vanniktech.maven.publish Gradle plugin and Sonatype Central Portal (no legacy Nexus staging URLs needed). | ||||
| - The plugin is configured to sign all publications. Coordinates and POM metadata are defined in build.gradle.kts. | ||||
| - If using the combined task is preferred, you can also run publishAndReleaseToMavenCentral when automatic release is enabled; this repository currently uploads with publishToMavenCentral from CI. | ||||
|  | ||||
| ## License | ||||
|  | ||||
| @@ -97,3 +171,5 @@ 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. | ||||
|  | ||||
| --- | ||||
|   | ||||
							
								
								
									
										136
									
								
								build.gradle.kts
									
									
									
									
									
								
							
							
						
						
									
										136
									
								
								build.gradle.kts
									
									
									
									
									
								
							| @@ -1,123 +1,88 @@ | ||||
| import org.jetbrains.kotlin.konan.properties.Properties | ||||
|  | ||||
| plugins { | ||||
|     kotlin("multiplatform") version "1.7.20" | ||||
|     id("org.jetbrains.dokka") version "1.7.20" | ||||
|     id("maven-publish") | ||||
|     kotlin("multiplatform") version "1.9.20" | ||||
|     id("org.jetbrains.dokka") version "1.9.20" | ||||
|     id("com.vanniktech.maven.publish") version "0.34.0" | ||||
|     signing | ||||
| } | ||||
|  | ||||
| val PUBLISH_GROUP_ID = "com.github.adriankuta" | ||||
| val PUBLISH_ARTIFACT_ID = "tree-structure" | ||||
| val PUBLISH_VERSION = "3.0.1" | ||||
| val PUBLISH_ARTIFACT_ID = "tree-structure"    // base artifact; KMP will add -jvm, -ios*, etc. | ||||
| val PUBLISH_VERSION = "3.1.2" | ||||
|  | ||||
| val secretFile = File(rootProject.rootDir, "local.properties") | ||||
| if (secretFile.exists()) { | ||||
|     secretFile.reader().use { | ||||
|         Properties().apply { | ||||
|             load(it) | ||||
|         } | ||||
|     }.onEach { (name, value) -> | ||||
|         project.ext[name.toString()] = value | ||||
|     } | ||||
| } else { | ||||
|     project.ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") | ||||
|     project.ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") | ||||
|     project.ext["sonatypeStagingProfileId"] = System.getenv("SONATYPE_STAGING_PROFILE_ID") | ||||
|     project.ext["signingKeyId"] = System.getenv("SIGNING_KEY_ID") | ||||
|     project.ext["signingPassword"] = System.getenv("SIGNING_PASSWORD") | ||||
|     project.ext["signingKey"] = System.getenv("SIGNING_KEY") | ||||
|     project.ext["snapshot"] = System.getenv("SNAPSHOT") | ||||
| } | ||||
| val snapshot: String? by project | ||||
|  | ||||
| group = PUBLISH_GROUP_ID | ||||
| version = if (snapshot.toBoolean()) "$PUBLISH_VERSION-SNAPSHOT" else PUBLISH_VERSION | ||||
|  | ||||
| val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class) | ||||
| mavenPublishing { | ||||
|     // Central Portal + auto release when we call publishAndReleaseToMavenCentral | ||||
|     publishToMavenCentral(automaticRelease = false) | ||||
|     signAllPublications() | ||||
|  | ||||
| val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) { | ||||
|     dependsOn(dokkaHtml) | ||||
|     archiveClassifier.set("javadoc") | ||||
|     from(dokkaHtml.outputDirectory) | ||||
| } | ||||
|     coordinates(PUBLISH_GROUP_ID, PUBLISH_ARTIFACT_ID, version.toString()) | ||||
|  | ||||
| publishing { | ||||
|     publications { | ||||
|  | ||||
|         withType<MavenPublication> { | ||||
|             artifact(javadocJar) | ||||
|     pom { | ||||
|         name.set("Tree Data Structure") | ||||
|         description.set("Simple implementation to store object in tree structure.") | ||||
|         url.set("https://github.com/AdrianKuta/Tree-Data-Structure") | ||||
|  | ||||
|         licenses { | ||||
|             license { | ||||
|                 name.set("MIT License") | ||||
|                         url.set("https://www.mit.edu/~amini/LICENSE.md") | ||||
|                 url.set("https://opensource.org/licenses/MIT") | ||||
|                 distribution.set("repo") | ||||
|             } | ||||
|         } | ||||
|         developers { | ||||
|             developer { | ||||
|                 id.set("AdrianKuta") | ||||
|                 name.set("Adrian Kuta") | ||||
|                 email.set("adrian.kuta93@gmail.com") | ||||
|             } | ||||
|         } | ||||
|         scm { | ||||
|                     connection.set("scm:git:github.com/AdrianKuta/Tree-Data-Structure.git") | ||||
|                     developerConnection.set("scm:git:ssh://github.com/AdrianKuta/Tree-Data-Structure.git") | ||||
|                     url.set("https://github.com/AdrianKuta/Tree-Data-Structure/tree/master") | ||||
|                 } | ||||
|             url.set("https://github.com/AdrianKuta/Tree-Data-Structure") | ||||
|             connection.set("scm:git:https://github.com/AdrianKuta/Tree-Data-Structure.git") | ||||
|             developerConnection.set("scm:git:ssh://git@github.com/AdrianKuta/Tree-Data-Structure.git") | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
|     repositories { | ||||
|         maven { | ||||
|             name = "Sonatype" | ||||
|             val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" | ||||
|             val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" | ||||
|             url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl) | ||||
|             credentials { | ||||
|                 val ossrhUsername: String? by project | ||||
|                 val ossrhPassword: String? by project | ||||
|                 username = ossrhUsername | ||||
|                 password = ossrhPassword | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| signing { | ||||
|     val signingKeyId: String? by project | ||||
|     val signingPassword: String? by project | ||||
|     val signingKey: String? by project | ||||
|     useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) | ||||
|  | ||||
|     sign(publishing.publications) | ||||
| } | ||||
| // No legacy publishing {} block or s01 repos — Central Portal handles it. | ||||
|  | ||||
| repositories { | ||||
|     mavenCentral() | ||||
| } | ||||
|  | ||||
| java { | ||||
|     toolchain { | ||||
|         languageVersion.set(JavaLanguageVersion.of(21)) | ||||
|     } | ||||
| } | ||||
| kotlin { | ||||
|     jvmToolchain(21); | ||||
|     jvm { | ||||
|         compilations.all { | ||||
|             kotlinOptions.jvmTarget = "1.8" | ||||
|         } | ||||
|         withJava() | ||||
|         testRuns["test"].executionTask.configure { | ||||
|             useJUnitPlatform() | ||||
|         } | ||||
|     } | ||||
|     js(BOTH) { | ||||
|         browser { | ||||
|             commonWebpackConfig { | ||||
|                 cssSupport.enabled = true | ||||
|             kotlinOptions { | ||||
|                 jvmTarget = "21"   // <- was "1.8" | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // JS targets (IR) for publishing | ||||
|     js(IR) { | ||||
|         browser() | ||||
|         nodejs() | ||||
|     } | ||||
|  | ||||
|     // iOS targets | ||||
|     iosX64() | ||||
|     iosArm64() | ||||
|     iosSimulatorArm64() | ||||
|  | ||||
|     // Native host target | ||||
|     val hostOs = System.getProperty("os.name") | ||||
|     val isMingwX64 = hostOs.startsWith("Windows") | ||||
|     val nativeTarget = when { | ||||
| @@ -127,23 +92,24 @@ kotlin { | ||||
|         else -> throw GradleException("Host OS is not supported in Kotlin/Native.") | ||||
|     } | ||||
|  | ||||
|  | ||||
|     sourceSets { | ||||
|         val commonMain by getting | ||||
|         val commonTest by getting { | ||||
|             dependencies { | ||||
|                 implementation(kotlin("test")) | ||||
|             } | ||||
|         } | ||||
|         val jvmMain by getting { | ||||
|             dependencies { | ||||
|                 implementation(kotlin("script-runtime")) | ||||
|             } | ||||
|         } | ||||
|         val commonTest by getting { dependencies { implementation(kotlin("test")) } } | ||||
|         val jvmMain by getting { dependencies { implementation(kotlin("script-runtime")) } } | ||||
|         val jvmTest by getting | ||||
|         val jsMain by getting | ||||
|         val jsTest by getting | ||||
|         val nativeMain by getting | ||||
|         val nativeTest by getting | ||||
|  | ||||
|         // Shared iOS source sets | ||||
|         val iosMain by creating { dependsOn(commonMain) } | ||||
|         val iosTest by creating { dependsOn(commonTest) } | ||||
|         val iosX64Main by getting { dependsOn(iosMain) } | ||||
|         val iosArm64Main by getting { dependsOn(iosMain) } | ||||
|         val iosSimulatorArm64Main by getting { dependsOn(iosMain) } | ||||
|         val iosX64Test by getting { dependsOn(iosTest) } | ||||
|         val iosArm64Test by getting { dependsOn(iosTest) } | ||||
|         val iosSimulatorArm64Test by getting { dependsOn(iosTest) } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							| @@ -1,5 +1,7 @@ | ||||
| distributionBase=GRADLE_USER_HOME | ||||
| distributionPath=wrapper/dists | ||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||||
| networkTimeout=10000 | ||||
| validateDistributionUrl=true | ||||
| zipStoreBase=GRADLE_USER_HOME | ||||
| zipStorePath=wrapper/dists | ||||
|   | ||||
							
								
								
									
										41
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										41
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							| @@ -55,7 +55,7 @@ | ||||
| #       Darwin, MinGW, and NonStop. | ||||
| # | ||||
| #   (3) This script is generated from the Groovy template | ||||
| #       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt | ||||
| #       https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt | ||||
| #       within the Gradle project. | ||||
| # | ||||
| #       You can find Gradle at https://github.com/gradle/gradle/. | ||||
| @@ -80,13 +80,11 @@ do | ||||
|     esac | ||||
| done | ||||
|  | ||||
| APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit | ||||
|  | ||||
| APP_NAME="Gradle" | ||||
| # This is normally unused | ||||
| # shellcheck disable=SC2034 | ||||
| APP_BASE_NAME=${0##*/} | ||||
|  | ||||
| # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||||
| DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | ||||
| # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) | ||||
| APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit | ||||
|  | ||||
| # Use the maximum available, or set MAX_FD != -1 to use that value. | ||||
| MAX_FD=maximum | ||||
| @@ -133,22 +131,29 @@ location of your Java installation." | ||||
|     fi | ||||
| else | ||||
|     JAVACMD=java | ||||
|     which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||||
|     if ! command -v java >/dev/null 2>&1 | ||||
|     then | ||||
|         die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||||
|  | ||||
| Please set the JAVA_HOME variable in your environment to match the | ||||
| location of your Java installation." | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| # Increase the maximum file descriptors if we can. | ||||
| if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then | ||||
|     case $MAX_FD in #( | ||||
|       max*) | ||||
|         # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. | ||||
|         # shellcheck disable=SC2039,SC3045 | ||||
|         MAX_FD=$( ulimit -H -n ) || | ||||
|             warn "Could not query maximum file descriptor limit" | ||||
|     esac | ||||
|     case $MAX_FD in  #( | ||||
|       '' | soft) :;; #( | ||||
|       *) | ||||
|         # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. | ||||
|         # shellcheck disable=SC2039,SC3045 | ||||
|         ulimit -n "$MAX_FD" || | ||||
|             warn "Could not set maximum file descriptor limit to $MAX_FD" | ||||
|     esac | ||||
| @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then | ||||
|     done | ||||
| fi | ||||
|  | ||||
| # Collect all arguments for the java command; | ||||
| #   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of | ||||
| #     shell script including quotes and variable substitutions, so put them in | ||||
| #     double quotes to make sure that they get re-expanded; and | ||||
| #   * put everything else in single quotes, so that it's not re-expanded. | ||||
|  | ||||
| # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||||
| DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | ||||
|  | ||||
| # Collect all arguments for the java command: | ||||
| #   * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, | ||||
| #     and any embedded shellness will be escaped. | ||||
| #   * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be | ||||
| #     treated as '${Hostname}' itself on the command line. | ||||
|  | ||||
| set -- \ | ||||
|         "-Dorg.gradle.appname=$APP_BASE_NAME" \ | ||||
| @@ -205,6 +214,12 @@ set -- \ | ||||
|         org.gradle.wrapper.GradleWrapperMain \ | ||||
|         "$@" | ||||
|  | ||||
| # Stop when "xargs" is not available. | ||||
| if ! command -v xargs >/dev/null 2>&1 | ||||
| then | ||||
|     die "xargs is not available" | ||||
| fi | ||||
|  | ||||
| # Use "xargs" to parse quoted args. | ||||
| # | ||||
| # With -n1 it outputs one arg per line, with the quotes and backslashes removed. | ||||
|   | ||||
							
								
								
									
										11
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							| @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal | ||||
|  | ||||
| set DIRNAME=%~dp0 | ||||
| if "%DIRNAME%"=="" set DIRNAME=. | ||||
| @rem This is normally unused | ||||
| set APP_BASE_NAME=%~n0 | ||||
| set APP_HOME=%DIRNAME% | ||||
|  | ||||
| @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome | ||||
|  | ||||
| set JAVA_EXE=java.exe | ||||
| %JAVA_EXE% -version >NUL 2>&1 | ||||
| if "%ERRORLEVEL%" == "0" goto execute | ||||
| if %ERRORLEVEL% equ 0 goto execute | ||||
|  | ||||
| echo. | ||||
| echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||||
| @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||||
|  | ||||
| :end | ||||
| @rem End local scope for the variables with windows NT shell | ||||
| if "%ERRORLEVEL%"=="0" goto mainEnd | ||||
| if %ERRORLEVEL% equ 0 goto mainEnd | ||||
|  | ||||
| :fail | ||||
| rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||||
| rem the _cmd.exe /c_ return code! | ||||
| if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 | ||||
| exit /b 1 | ||||
| set EXIT_CODE=%ERRORLEVEL% | ||||
| if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||||
| if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||||
| exit /b %EXIT_CODE% | ||||
|  | ||||
| :mainEnd | ||||
| if "%OS%"=="Windows_NT" endlocal | ||||
|   | ||||
| @@ -8,7 +8,10 @@ import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators | ||||
| import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators.* | ||||
| import kotlin.jvm.JvmSynthetic | ||||
|  | ||||
| open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationInterface<T> { | ||||
| /** | ||||
|  * @param treeIterator Choose one of available iterators from [TreeNodeIterators] | ||||
|  */ | ||||
| open class TreeNode<T>(val value: T, var treeIterator: TreeNodeIterators = PreOrder) : Iterable<TreeNode<T>>, ChildDeclarationInterface<T> { | ||||
|  | ||||
|     private var _parent: TreeNode<T>? = null | ||||
|  | ||||
| @@ -33,11 +36,6 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn | ||||
|     val isRoot: Boolean | ||||
|         get() = _parent == null | ||||
|  | ||||
|     /** | ||||
|      * Choose one of available iterators from [TreeNodeIterators] | ||||
|      */ | ||||
|     var defaultIterator: TreeNodeIterators = PreOrder | ||||
|  | ||||
|     /** | ||||
|      * Add new child to current node or root. | ||||
|      * | ||||
| @@ -166,9 +164,9 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * You can change default iterator by changing [defaultIterator] property. | ||||
|      * You can change default iterator by changing [treeIterator] property. | ||||
|      */ | ||||
|     override fun iterator(): Iterator<TreeNode<T>> = when (defaultIterator) { | ||||
|     override fun iterator(): Iterator<TreeNode<T>> = when (treeIterator) { | ||||
|         PreOrder -> PreOrderTreeIterator(this) | ||||
|         PostOrder -> PostOrderTreeIterator(this) | ||||
|         LevelOrder -> LevelOrderTreeIterator(this) | ||||
|   | ||||
| @@ -19,8 +19,7 @@ inline fun <reified T> tree( | ||||
|     defaultIterator: TreeNodeIterators = TreeNodeIterators.PreOrder, | ||||
|     childDeclaration: ChildDeclaration<T> | ||||
| ): TreeNode<T> { | ||||
|     val treeNode = TreeNode(root) | ||||
|     treeNode.defaultIterator = defaultIterator | ||||
|     val treeNode = TreeNode(root, defaultIterator) | ||||
|     treeNode.childDeclaration() | ||||
|     return treeNode | ||||
| } | ||||
		Reference in New Issue
	
	Block a user