Skip to content

Add ArrayMap/ArraySet (slice-backed ordered map/set) and integrate into ds package#3

Merged
leaxoy merged 1 commit into
mainfrom
codex/add-arraymap-implementation-using-slice
May 16, 2026
Merged

Add ArrayMap/ArraySet (slice-backed ordered map/set) and integrate into ds package#3
leaxoy merged 1 commit into
mainfrom
codex/add-arraymap-implementation-using-slice

Conversation

@leaxoy
Copy link
Copy Markdown
Contributor

@leaxoy leaxoy commented May 16, 2026

Motivation

  • Provide a compact, slice-backed ordered map implementation with binary-search lookups and efficient iteration for small-to-medium maps via an ArrayMap backed by a sorted slice.
  • Provide an ArraySet built on top of ArrayMap to offer ordered set semantics and common set-algebra operations (Union, Intersection, Difference, SymmetricDifference, etc.).
  • Expose the new types and constructors from the top-level ds package and update docs/examples to advertise the new, lightweight ordered collection options.

Description

  • Added a new arraymap package implementing ArrayMap with core operations, Entry API (OrInsert, AndModify, Insert, Delete), range/iteration support (IterAsc, IterDesc, RangeAsc, RangeDesc, mutable variants), and helper constructors New, NewOrdered, and NewFromMap (files: arraymap.go, entry.go, iter.go, doc.go).
  • Added a new arrayset package implementing ArraySet backed by ArrayMap, including ordering, range iteration, set algebra methods, and convenience constructors (files: arrayset.go, iter.go, doc.go).
  • Integrated the new types into the top-level ds package by adding aliases and constructors such as ArrayMap, NewArrayMap, NewOrderedArrayMap, ArraySet, NewArraySet, and NewOrderedArraySet, and reorganized some doc exports in ds.go to include the new structures.
  • Updated README.md and package docs to list ArrayMap/ArraySet and added a small example showing usage with cmp.Compare.

Testing

  • Ran go test ./... across the module and the test suite completed successfully.
  • Added comprehensive unit tests for arraymap (arraymap_test.go) covering ordering, entry API, iteration, range/mutation, cloning/clearing, and constructors, and all tests passed.
  • Added unit tests for arrayset (arrayset_test.go) covering basic operations, ordering and ranges, set algebra, and clone semantics, and all tests passed.

Codex Task

@leaxoy leaxoy marked this pull request as ready for review May 16, 2026 12:30
@leaxoy leaxoy merged commit 0a1df34 into main May 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant