Skip to content

Refactor HashTableSeparateChaining: encapsulate Entry, fix iterator, simplify API#1316

Merged
williamfiset merged 1 commit intomasterfrom
refactor-hashtable-separate-chaining
Apr 3, 2026
Merged

Refactor HashTableSeparateChaining: encapsulate Entry, fix iterator, simplify API#1316
williamfiset merged 1 commit intomasterfrom
refactor-hashtable-separate-chaining

Conversation

@williamfiset
Copy link
Copy Markdown
Owner

Summary

  • Make Entry a private static inner class instead of top-level package-private
  • Remove redundant method aliases (add/insert/hasKey) — keep put/containsKey
  • Add dedicated modCount for fail-fast iteration (was using size as proxy)
  • Rewrite iterator so hasNext() is idempotent and doesn't advance state
  • Use single-pass iterator removal in removeEntry to avoid double linear scan
  • Remove unnecessary bucket.clear() in resizeTable
  • Add educational comments on key implementation details

Test plan

  • bazel test //src/test/java/com/williamfiset/algorithms/datastructures/hashtable:HashTableSeparateChainingTest — all tests pass

🤖 Generated with Claude Code

…simplify API

Make Entry a private static inner class. Remove redundant method aliases
(add/insert/hasKey) in favor of put/containsKey. Add dedicated modCount
for fail-fast iteration instead of using size as a proxy. Rewrite iterator
so hasNext() is idempotent. Use single-pass iterator removal in removeEntry
to avoid double linear scan. Remove unnecessary bucket.clear() in resize.
Add educational comments on key implementation details.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@williamfiset williamfiset merged commit a236008 into master Apr 3, 2026
2 checks passed
@williamfiset williamfiset deleted the refactor-hashtable-separate-chaining branch April 3, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant