feat(math): Clojure hash-map iteration order for the in-conv greedy tie-break (legacy)#2650
Draft
jucor wants to merge 1 commit into
Draft
feat(math): Clojure hash-map iteration order for the in-conv greedy tie-break (legacy)#2650jucor wants to merge 1 commit into
jucor wants to merge 1 commit into
Conversation
This was referenced Jul 22, 2026
Draft
docs(delphi): R1-parity goal docs, journal (2026-07-18 → 07-24 s5), quirks + divergence ledger
#2626
Draft
Draft
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores Clojure-legacy parity for the in-conversation (“in-conv”) greedy-floor tie-break by reproducing Clojure PersistentHashMap iteration order (Murmur3 hashLong + HAMT 5-bit chunk traversal) for integer (and numeric-string) keys, and using that ordering as the stable-sort tie base.
Changes:
- Add
polismath.utils.clj_hashimplementing ClojurehashLongand HAMT-based key iteration order for int-like keys (with a documented fallback). - Update legacy-mode greedy-floor candidate ordering in
Conversation._get_in_conv_participantsto follow Clojure hash-map iteration order on equal vote-count ties. - Add targeted unit/integration tests that pin known hash/HAMT order and validate the greedy-floor tie outcome for both int and string pid shapes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
delphi/tests/test_clj_hash_order.py |
Adds regression tests for Clojure hash-map key order and legacy greedy-floor tie behavior (int + string pids). |
delphi/polismath/utils/clj_hash.py |
Implements Murmur3 hashLong and a HAMT-path-based ordering function to emulate Clojure PersistentHashMap iteration order. |
delphi/polismath/conversation/conversation.py |
Switches legacy greedy-floor tie-breaking to Clojure hash-map order by pre-ordering candidates before stable vote-count sorting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest |
Comment on lines
+18
to
+21
| Caveats, deliberate and documented: | ||
| - Integer keys only. Other key types hash differently (e.g. String hasheq is | ||
| Murmur3 over ``String.hashCode``); :func:`clojure_hash_map_key_order` falls | ||
| back to the given order for them rather than guessing. |
Comment on lines
+2067
to
+2071
| candidates = [ | ||
| pid for pid in clojure_hash_map_key_order(vote_counts.keys()) | ||
| if pid not in in_conv | ||
| ] | ||
| candidates.sort(key=lambda pid: -vote_counts[pid]) # stable -> clj-map ties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The greedy floor (conversation.clj:259-268) sorts the user-vote-counts
hash-map with a STABLE sort by count desc — so equal-count ties follow
Clojure's PersistentHashMap ITERATION ORDER, which is deterministic:
sort by successive 5-bit chunks (low first) of Murmur3 hashLong
(Clojure hasheq for Long keys). Validated against three recorded-blob
oracles (user-vote-counts raw key order: vw front-loaded6 n=18, vw
uniform8 n=30, biodiversity n=98 — all exact).
The PR-E port assumed this order was non-deterministic and substituted
matrix row order; on vw front-loaded6 step 0 that admits pid 14 where
Clojure admits pid 17 (five-way 1-vote tie at the floor boundary),
seeding an in-conv/base-cluster membership divergence that cascades
through every downstream key — the battery's last diverging entry.
Adds polismath/utils/clj_hash.py (hashLong + HAMT key order; int keys
only, with a documented row-order fallback otherwise) and applies it to
the legacy greedy candidate order. Array-map (≤8 entries, insertion
order) cannot affect the pick: ties only matter with ≥16 participants,
which guarantees hash-map. Improved mode unchanged.
commit-id:d5f1f51d
Stack: