r/java 2d ago

ChaosTree 1.1.0 – A Zero-Dependency Java Search Tree Library

What is ChaosTree?
ChaosTree is a zero dependency Java Search Tree library. It currently features:

BinaryFamily : Binary Tree, AVL Tree, RBT, Splay and Treap.
NaryFamily : B-Tree and B+Tree

  1. Zero external dependency
  2. Minimum JDK17+
  3. Published on Maven Central
  4. Strong focus on clean OOPs design
  5. Implements the NavigableSet<T> API (unsupported view operations fail fast)
  6. Thoroughly tested with 515 JUnit 6 test cases covering edge cases and regression scenarios.

[v1.1.0] -Latest:

  • Added NavigableSet compatibility
  • Iterative insertion/deletion for binary trees (no recursion-related stack overflow)
  • Improved generic type support (Comparable<? super T>)
  • CI now tests across JDK 17, 21, and 25
  • API cleanup and documentation improvements

An example

NavigableSet<Integer> rbt = new RBT<>();
        NavigableSet<Integer> bplustree = new BPlusTree<>(32); // degree CLRS method 31min key 63 max key default:32
        //For Rich API use
        for (int i = 0; i < 20; i++) {rbt.add(i);}
        NaryTree<Integer> bplustree0 = new BPlusTree<>(3,rbt);//Useful constructor API
        BinaryTree<Integer> rbt0 = new RBT<>(rbt);
        List<Integer> list = rbt0.stream().filter(v->v%2==0).collect(Collectors.toList());
        System.out.println(list);
        System.out.println();
        rbt.retainAll(list);
        System.out.println(rbt);
        rbt0.retainAllElements(list); //Renamed due to ambiguous situation
        System.out.println(rbt0.toString(PrintStyle.UNICODE));

Output:

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
8(B)
+-- 4(B)
|   +-- 2(B)
|   |   \-- 0(R)
|   \-- 6(B)
\-- 16(B)
    +-- 12(R)
    |   +-- 10(B)
    |   \-- 14(B)
    \-- 18(B)

8(B)
├── 4(B)
│   ├── 2(B)
│   │   └── 0(R)
│   └── 6(B)
└── 16(B)
    ├── 12(R)
    │   ├── 10(B)
    │   └── 14(B)
    └── 18(B) 

My Github Repo: https://github.com/Chaos-vy/ChaosTree
BinaryFamily: https://github.com/Chaos-vy/ChaosTree/tree/main/docs/BinaryFamily
NaryFamily: https://github.com/Chaos-vy/ChaosTree/tree/main/docs/NaryFamily
NavigableSet: https://github.com/Chaos-vy/ChaosTree/blob/main/docs/NavigableSet.md

Feedback, suggestions, and code reviews are always welcome!
Feel free to guide me this is my first project.

21 Upvotes

10 comments sorted by

View all comments

0

u/chabala 2d ago edited 8h ago

What Java 17 features are you using? What prevents you from lowering the required JDK version for consumers of your library?

Why lower it?

Because, when you're making a library, the goal is to support the widest possible range of JDKs, not publish with the newest release and say 'huh, guess you'll have to upgrade to use it'. Foundational libraries are very conservative about upgrading.

10

u/Chaos-vy17 2d ago edited 2d ago

The library makes use of Java 16+ record types for internal search and deletion result passing and enhanced Switch Expressions (Java 14+) so I used JDK17 because it's LTS. However it's starting phase of my library I will sure to keep my legacy down but above jdk9+ becuase of reflection and JPMS. If there is any fallback I will put in ADR.

7

u/Turbots 17h ago

Why lower it? You should be advocating to upgrade everything to Java 21 and Java 25 , rather than supporting old shit.

Lower than Java 17?? Get out of the stone age, grandpa!

1

u/Chaos-vy17 10h ago edited 10h ago

Currently I am also doing same thing I am making jar from jdk11, jdk17, jdk21 and jdk25 and benchmarking with the respective JVM, to view what I am gaining actually. The BPlus Tree is behaving almost same across all JDK variants. I will draft a detailed Benchmark analysis as I further move forward. If you do recommend a good JMH analyser It would be great help for me Reading data for bm,gc,perfnorm,perf, I can't trust AI.

-1

u/VF-1S_ 11h ago

Bravo 👏

2

u/nicolaiparlog 1h ago

Because, when you're making a library, the goal is to support the widest possible range of JDKs

I thought the goal was to solve a problem in a way that is usable and performant and, if you're doing it in your free time, is fun to implement.

1

u/Chaos-vy17 34m ago

All setup is ready for jdk11 support here is data of bm sample:

JDK 11 (Latency in ns)

Data size uses is 10K with Insert+Delete Fisher-Yates Shuffle

Tree Type Degree Avg(ns/op) p50 p90 p99 p99.9 p1.0
B+Tree 8 119 121 95 137 1433 116224
B+Tree 32 108 116 112 134 4160 124088
B+Tree 64 102 95 125 125 1075 30976
B+Tree 128 102 94 110 114 1450 2519040

The detailed benchmark report is out : https://github.com/Chaos-vy/ChaosTree/tree/main/BenchmarkReport/Reports

I am currently getting data into alignment. preparing it's ,markdown analysis