logoalt Hacker News

shadowgovtyesterday at 3:11 PM1 replyview on HN

Regarding the spooky-action-at-a-distance concerns of a `.freeze()` method on dict:

`.freeze()` should probably just return a frozendict instead of in-place mutating the dict, and they should be separate types. Under the hood, you'll have to build the hashtable anyway to make the frozendict; as long as you're doing that work, you may as well build an object to contain the hashtable and just have that object be separate from the dict that birthed it.

The values referenced by both the original dict and the frozendict can be the same values; no need to clone them.


Replies

emil-lptoday at 7:58 AM

The point is that freeze could work in constant time, whereas the copying takes linear time.

Another alternative mentioned was `move`, which would create a frozen version in constant time and clear the original dict.