Repository navigation
Conversation
A defndynamic resolves names from the root, not its module, so the unqualified dflt-len in shrink was not found. Use Map.dflt-len, as the other dynamic Map functions do with Map.min-load. Fixes carp-lang#1600.
|
Hi Berce, and thanks for contributing. Just one question: what was the role of AI assistance in this patch? We’re not against AI-assisted development, but we ask that people are transparent about it. Also, especially on issues marked "beginner", we’re mostly interested in people who want to start engaging with the project rather than drive-by contributions. |
|
hi, honest answer: the code was written by claude code, and i tested it locally before opening the PR (built carp with gcc and ran the test suite, including the new tests). totally get the point about beginner issues, if you'd rather keep those for people starting out with the project i'm fine closing this one |
|
thanks for your candor! was this meant more of a drive-by, or did you want to enter the community? if it’s the former no hard feelings at all, but i think we should close this. |
|
not meant as a drive-by, i'd like to stick around and keep contributing, mostly fixes through PRs like this one. if that works for you i'm happy to keep this and #1608 open and work through any review |
|
works for me! feel free to join the discord, too, since that’s where the chatter happens :) |
put grew once the load passed min-load instead of max-load. remove shrank while the load was above min-load and only filtered the bucket afterwards, rebuilding the bucket list in reverse, so the other keys could land in the wrong buckets. It now drops the key from its bucket and shrinks one step when the load falls below min-load, like the static Map.
|
good catch, pushed fixes for both: |
| (if (and (< (/ (* (Map.len removed) 100) (length removed)) Map.min-load) | ||
| (> (length removed) Map.dflt-len)) | ||
| (Map.shrink removed) | ||
| removed))) |
There was a problem hiding this comment.
The doc says a missing key returns the map unchanged, but we now check the siz and shrink first.
There was a problem hiding this comment.
right, fixed in cf5338c: remove now returns the map as is when the key isn't there, so the doc holds again. added a test for that (a sparse 64-slot map keeps its size when you remove a missing key). full run_carp_tests.sh passes.
| (let [idx (Dynamic.imod (hash k) (length m)) | ||
| removed (List.update-nth m idx (fn [l] (filter (fn [pair] (/= (car pair) k)) l)))] | ||
| (if (and (< (/ (* (Map.len removed) 100) (length removed)) Map.min-load) | ||
| (> (length removed) Map.dflt-len)) |
There was a problem hiding this comment.
(> (length removed) Map.dflt-len) is already in shrink. calling shrink on thefirst condition is enough.
|
right, dropped it. |
Fixes #1600.
went with what you found in the comment:
shrinkuseddflt-lenunqualified, and adefndynamicresolves from the root, so it never saw the dynamic one in the Map module. it'sMap.dflt-lennow, same as the other funs useMap.min-load.added two tests to
test/dynamic_map.carp: shrinking a fresh map leaves it at 16 buckets, and shrinking a 64 bucket map gives 32. on master that file now stops withCan't find symbol 'dflt-len' at core/Map.carp:711:25, with the fix all 37 tests in it pass.i ran the other
test/*.carpfiles too, same results as master apart from the new tests (init_global, managed, memory and unsafe don't pass in my container on master either, so i left those alone).