Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 2.88 KB

File metadata and controls

47 lines (32 loc) · 2.88 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

A pure Java repository of hand-written data structure implementations and LeetCode solutions. There is no build tool (no Maven/Gradle) — source files are compiled and run directly via javac/java from the src/ root.

Build & Run

Compile and run from the src/ directory:

cd src
javac com/ds_algo/z_sorts/TestMain.java    # compile a Main class (pulls in dependencies)
java com.ds_algo.z_sorts.TestMain           # run it

Each data structure package has its own Main or Test*Main class as an entry point. There is no test framework — verification is done by running these main classes.

Architecture

All source lives under src/com/:

  • ds_algo/ — Data structures, alphabetically prefixed (a_ through z_), each self-contained:

    • Linear: ArrayList, LinkedList (single, circular), Stack, Queue (circular, deque)
    • Trees: BST → BinaryTree → BBST → AVLTree / RBTree (inheritance chain in f_BST/, g_AVLTree/, h_RBTree/)
    • Collections: Set (List/Tree), Map (TreeMap), HashMap (red-black tree buckets with LinkedHashMap), HashSet
    • Advanced: Heap, PriorityQueue, Huffman coding, Trie, UnionFind (multiple optimization variants), Graph (adjacency list with BFS/DFS/Dijkstra/Bellman-Ford/Floyd/Prim/Kruskal/topological sort)
    • Sorting: z_sorts/ — abstract Sort<T> base class with comparison sorts (cmp/) and non-comparison sorts (Counting, Radix, Bucket)
  • leetcode/ — LeetCode solutions organized by topic (array, binaryTree, dfs, dp, graph, linkedList, priorityQueue, queue, stack). File naming: _<number>_<Chinese description>.java.

  • tool/ — Shared utilities:

    • binaryTree/printer/ — Binary tree pretty-printer (implements BinaryTreeInfo interface)
    • common/Asserts, Integers (random array generation), TimeTool, file utilities

Key Design Patterns

  • The tree hierarchy uses a layered inheritance: BinaryTreeBSTBBSTAVLTree/RBTree. Adding a new balanced tree means extending BBST.
  • Sort<T> is an abstract base that tracks compare/swap counts and timing. Concrete sorts override the sort() template method. SortFactory creates sort instances for benchmarking.
  • Graph<V, E> is abstract with a WeightManager<E> strategy for generic edge weights. ListGraph is the adjacency-list implementation.
  • HashMap uses red-black tree nodes for collision resolution (not linked lists), defined inline as HashMap.Node.
  • UnionFind has progressive optimization variants: QF → QU → QU+Size → QU+Rank → QU+Rank+PathCompression/PathHalving/PathSplitting. UnionFindGeneric<V> wraps int-based UnionFind for arbitrary value types.

Language

Comments and class names are in Chinese. LeetCode file names use Chinese descriptions after the problem number.