Skip to content
CAI
Software that uses CAICheck a score

kanwei/algorithms

61.5

Adequate · 6 November 2026

2.4k

lines of production code

Ruby

with C

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a Ruby gem providing high-performance data structures and algorithms, implemented primarily as C extensions for speed with Ruby fallbacks for compatibility. It offers a modular library of containers such as deques, heaps, red-black trees, splay trees, tries, and KD-trees, alongside algorithmic modules for sorting, searching, and string manipulation like Levenshtein distance. The codebase includes comprehensive benchmarks and tests to validate the performance and correctness of these native implementations.

Features

Add Binary Search Tree (BST) container extension

Introduces a new Binary Search Tree container implemented as a Ruby C extension (CBst). This addition provides a keyed collection that supports insertion, deletion, search, and iteration, with optimized comparison logic for Fixnum and String keys to improve performance over generic object comparison.

ext/containers/bst · high confidence

Add C-based Deque container extension

A new C extension named CDeque has been added to provide a deque (double-ended queue) data structure. This implementation exposes methods for adding and removing elements from both the front and back of the queue, as well as querying the size, checking if the queue is empty, clearing the contents, and iterating through elements in both forward and backward directions. The extension is built using Ruby's C API and includes garbage collection support to properly manage memory for the stored objects.

ext/containers/deque · high confidence

Add C-based SplayTree and RBTree map implementations

This change introduces two new native C extensions for Ruby: \CSplayTreeMap\ and \CRBTreeMap\. The \ext/containers/splaytree\_map\ directory now contains the implementation for a splay tree map, providing optimized insertion, retrieval, and deletion operations that splay accessed nodes to the root. Similarly, the \ext/containers/rbtree\_map\ directory adds a red-black tree map implementation, ensuring balanced tree structures for consistent performance. These extensions offer high-performance, memory-efficient alternatives to pure Ruby hash implementations for ordered key-value storage.

_ext/containers/splaytree\map · high confidence

Add Levenshtein distance calculation to String algorithms

A new C extension for string algorithms has been added, introducing the \Algorithms::String.levenshtein\_dist\ method. This feature calculates the Levenshtein distance (edit distance) between two strings, implemented in C for performance and integrated into the existing \Algorithms\ module structure.

ext/algorithms · high confidence

New data structures: Deque, KDTree, SuffixArray, and Trie

The containers library now includes several new data structures. A Deque (double-ended queue) is available, implemented in C with a Ruby fallback, allowing O(1) additions and removals from both ends. A KDTree supports nearest-neighbor searches in multi-dimensional space. A SuffixArray enables fast substring searches via binary search on sorted suffixes. A Trie (specifically a Ternary Search Tree) provides O(m) key lookups and supports wildcard matching and longest-prefix queries. These new containers are added alongside existing ones like Heap, PriorityQueue, Queue, Stack, RBTreeMap, and SplayTreeMap.

lib/containers · high confidence

New search, sorting, and string algorithm modules

The library now includes three new algorithm modules: \Algorithms::Search\ provides binary search and the Knuth-Morris-Pratt (KMP) substring search; \Algorithms::Sort\ implements multiple sorting algorithms including bubble, comb, selection, heap, insertion, shell, and quicksort; and \Algorithms::String\ provides string algorithm support via an optional C extension.

lib/algorithms · high confidence

Removals

Removal of bin/algorithms script

The executable script located at bin/algorithms has been removed from the project. This change eliminates the specific algorithmic tool or entry point that was previously available in this location.

bin · high confidence

Removal of legacy data structure implementations

The legacy implementations for Stack, Heap, Hash, Priority Queue, and Queue have been removed from the library. This cleanup eliminates stubbed or incomplete classes (such as the placeholder Heap class and the basic Stack wrapper) that were previously part of the data structures module, likely to make way for more robust or distinct implementations introduced in other parts of the codebase.

lib/datastructures · high confidence

Behavioural changes

Library restructured into modular algorithms and containers with expanded feature set

The library has been reorganized from a single monolithic class into modular namespaces (Algorithms and Containers), providing users with a broader range of data structures and algorithms. Users can now access heaps, stacks, queues, deques, priority queues, red-black trees, splay trees, tries, suffix arrays, and KD-trees via the Containers module, alongside search, sorting (including dual-pivot quicksort), and string algorithms (like Levenshtein distance) via the Algorithms module. The main entry point now requires these specific sub-modules, enabling more granular usage and better organization of the available functionality.

lib · high confidence

Migration to Bundler and Rake ExtensionTask for build process

The project's build system has been updated to replace the Echoe gem with Bundler and Rake's native ExtensionTask. This change modifies the Rakefile to explicitly define C extension tasks (such as CString, CDeque, CBst, CRBTreeMap, and CSplayTreeMap) and integrates RSpec for testing, ensuring that C extensions are compiled by default on non-JRuby platforms before running specs. Additionally, legacy text-based documentation files (History.txt, Manifest.txt, README.txt) have been removed in favor of Markdown equivalents (CHANGELOG.markdown, ALGORITHM\_INFO.md, README.markdown), and a .gitignore file has been added to exclude build artifacts and IDE files.

(repo-wide) · high confidence

Test coverage

Add benchmarks for deque, heap, sort, and treemap operations; Added comprehensive test coverage for data structures and algorithms.

Dependencies

Initial release of the algorithms gem (v1.1.0)

This change introduces the initial packaging of the 'algorithms' Ruby gem, version 1.1.0, which provides data structures (such as heaps, priority queues, deques, stacks, queues, red-black trees, splay trees, and tries) and sorting algorithms. The package includes optional C extensions for performance on standard Ruby, while supporting JRuby via Java platform specifications. Development dependencies for testing and compilation (rspec, rake-compiler) are established via a new Gemfile and Gemfile.lock.

(dependencies) · high confidence

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 59 → 62 (+2.7)
  • Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.

Lenses

  • Code Health 74 → 74 (+0.0)
  • Architecture 100 → 100 (+0.0)
  • Maturity 41 → 48 (+6.1)
  • Readiness 63 → 63 (+0.0)
  • Security 97 → 95 (-1.9)

Resolved (4)

  • Inconsistent method signatures for search operations. binary_search takes a container and an item, while kmp_search has two overloads: one taking a string and substring, and another taking only a substring (implying it operates on an internal state or default string, which is not visible in the signature). This inconsistency in parameter requirements makes the API unpredictable.
  • Inconsistent naming for existence checks and lookups. RBTree, SplayTree, and Trie use get(key) for retrieval and has_key?(key) for existence. Heap uses has_key? but also has next() for peeking. PriorityQueue uses has_priority?. There is no consistent contains(key) or exists(key) method. Additionally, get implies retrieval, while has_key? implies boolean check, which is consistent, but the lack of a unified contains or has method across all types (e.g., Deque doesn't have has_item?) is an inconsistency.
  • Inconsistent naming for insertion operations. Most associative containers (RBTree, SplayTree, Trie, Heap) and simple containers (Queue, Stack) use push. However, PriorityQueue uses push but with a different signature (object, priority) compared to Heap (key, value), and Deque uses push_front/push_back instead of a generic push. This forces the user to remember specific method names based on the container type rather than a unified interface.
  • Inconsistent naming for peek vs. remove operations. Queue, Stack, PriorityQueue, and Heap all expose both next() (peek) and pop() (remove). However, RubyRBTreeMap and RubySplayTreeMap use get(key) for lookup and delete(key) for removal, lacking a consistent 'peek' method for the head/min element. Furthermore, next() is a non-standard name for 'peek' in this context, while pop is standard for removal. The mix of next/pop and get/delete creates confusion about whether an operation is destructive.

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

kanwei/algorithms was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 6 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 72bb2c8e0d2049821538819749cd3a9b0fddd9cd — the exact code this score is about.
  • Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
  • Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.2+preprod-5c4e66d9318b.