Skip to content

Latest commit

 

History

History
80 lines (62 loc) · 3.53 KB

File metadata and controls

80 lines (62 loc) · 3.53 KB

Gemini CLI - Algorithms & Data Structures (Java)

This repository contains a collection of common data structures and algorithms implemented in Java, with a focus on simplicity and elegance.

Project Overview

  • Main Technologies: Java (JDK 8+), Bazel (Build System).
  • Core Goal: Demonstrate correct and efficient implementations of algorithms.
  • Architecture: Organized into thematic packages (e.g., datastructures, graphtheory, dp).
  • Dependencies: Managed via Bazel's MODULE.bazel using rules_jvm_external. Key dependencies include JUnit 5, Guava, and Mockito.

Building and Running

Using Bazel (Recommended)

Bazel is the primary build system. Each package contains a BUILD file defining libraries and binaries.

  • Run an algorithm:

    bazel run //src/main/java/com/williamfiset/algorithms/<subpackage>:<ClassName>

    Example: bazel run //src/main/java/com/williamfiset/algorithms/search:BinarySearch

  • Run all tests:

    bazel test //src/test/...
  • Run tests for a specific package:

    bazel test //src/test/java/com/williamfiset/algorithms/<subpackage>:all
  • Run a specific test class:

    bazel test //src/test/java/com/williamfiset/algorithms/<subpackage>:<TestClassName>

Using only JDK

If Bazel is not available, you can compile and run manually:

mkdir -p classes
javac -sourcepath src/main/java -d classes src/main/java/com/williamfiset/algorithms/<path>/<File>.java
java -cp classes com.williamfiset.algorithms.<package>.<ClassName>

Development Conventions

Documentation and Comments

  • Educational Context: This repository is an educational project. Most comments (except for the most trivial ones) must be preserved during refactoring.
  • Purpose: Comments should explain how and why an algorithm or data structure works to aid understanding for students and developers.
  • Refactoring: When simplifying code, ensure that the conceptual explanations remain intact.

Project Structure

  • src/main/java/com/williamfiset/algorithms/: Implementation source code.
  • src/test/java/com/williamfiset/algorithms/: Unit tests (mirrors source structure).
  • utils/: Contains helper classes like GraphGenerator and graph Utils.

Adding a New Algorithm

  1. Implementation: Add the .java file to the appropriate package in src/main/java/....
  2. Bazel Configuration:
    • Add the file to the java_library's srcs in the package's BUILD file (usually handled by glob).
    • Add a java_binary target for the class if it has a main method.
  3. Testing:
    • Create a corresponding test file in src/test/java/....
    • Use JUnit 5 (Jupiter) for new tests.
    • Add a java_test target in the test directory's BUILD file.
  4. Documentation: Update the README.md with a link to the new implementation and its complexity.

Coding Patterns

  • Solvers: Many algorithms are implemented as "Solver" classes where you instantiate, provide input (e.g., add edges), and then call a solve() or specific getter method.
  • Graph Representation: Adjacency lists are commonly represented as List<List<Edge>> or List<List<Integer>>.
  • Flow Algorithms: Share a common base NetworkFlowSolverBase.

Key Files

  • README.md: Comprehensive list of all implemented algorithms and data structures.
  • MODULE.bazel: Defines external dependencies and Bazel module configuration.
  • CLAUDE.md: Additional technical guidance for AI assistants.
  • BUILD.bazel / BUILD: Bazel build definitions.