02:57
<Jack Works>
oh I wonder what's the motivation for BigInt TAs
02:58
<Jack Works>
I thought TA is for low level calculations, is there a cross-platform representation (like IEEE floating points) for BigInt?
02:58
<shu>
oh the TAs aren't actually storing BigInts, they're storing (u)int64
02:59
<shu>
but to get the values out / or assign into them we need to put them into BigInts
02:59
<shu>
since Numbers don't have enough bits to hold int64s
03:01
<Jack Works>
🤔 so it cannot store infinitely big number?
03:02
<Jack Works>
oh I see
08:46
<Domenic>

So here is a fun case. On the web platform we have Headers, which is supposed to be Map-like. However, we want its entries to be sorted (based on their keys), when iterating.

OK. So what happens if you mutate during iteration? In particular, consider starting with keys ["a", "c", "d"]. "a" is visited. "c" is visited. At this point "b" is inserted. Now what?

If we naively copy Map's iteration algorithm, we get ["a", "c", "c", "d"], since "c" moved from index 1 to index 2 when we inserted "b".

We could output ["a", "c", "b", "d"] (breaking the ordering invariant), or ["a", "c", "d"] (breaking the invariant that things added during iteration are always visited). Or we could stick with the natural extension of Map's behavior and do ["a", "c", "c", "d"]. Which is least-bad?

08:58
<Robert Pamely>
I haven't run this, but from what I can tell in c++ it would just move on to "d" because "b" is behind the iterator. That's logically what I would expect myself.
09:01
<Robert Pamely>
So I guess that's the middle option you gave reading again. If you insert during iteration you could miss elements.
09:28
<Ashley Claymore>
TIL, Map delete doesn't actually remove the entry from the list (but implementations can avoid the memory leak)
09:29
<Ashley Claymore>
let m = new Map();
[..."abcde"].forEach(m.set.bind(m));

for (const [k] of m) {
  console.log(k);
  if (k === "c") m.delete("b");
}


〠> a
〠> b
〠> c
〠> d
〠> e
09:33
<Ashley Claymore>
so to see a map key twice looks like need to delete and then re-set
09:35
<Ashley Claymore>
I'm +1 on Robert Pamely . Inserting behind the sorted position of the iterator would result in that entry not being seen, and the current entry not being seen twice
15:45
<bakkot>
+1 to ["a", "c", "d"]; that's also consistent with e.g. Java's ConcurrentSkipListMap and separately I think is the least unexpected from first principles
15:45
<bakkot>
I think for sorted collections you should not expect that things added during iteration are necessarily visited