MapOf
- Document zero value in the context of Load
and whether or not it applies to deleted items during Range
#119
Labels
The godoc for
MapOf.Load
states the following (emphasis mine):This is probably a copy-and-paste from the non-generic map implementation, since it does not make sense in the context of a generic data structure when the return type is not a pointer. To be more concrete, there cannot be a
nil
return fromMapOf[string, string].Load()
, so it should probably read something like:This brings up a related question about
MapOf.Range
. The godoc there says (emphasis mine):Here "any mapping" makes sense in the storage context --if one or more Ps stores a value while we are iterating, we might see any one of them or none at all-- but it is unclear what "any mapping" means in the case of deletion. What happens if an entry is deleted before iteration reaches it? Are we guaranteed to never see it, or could we get the zero value instead? The docs here should be specific, since range does not give us any indication if the value we're seeing might have been deleted. This means that, if it is important to us not to use a deleted value in
Range
, we need to synthesize a way to do it ourselves using the zero value of the type. In the case of primitive types, this would mean never storing the zero value directly, while in the case of structs, it would mean ensuring that at least one field is never stored with a zero value, so that we can can use it to check if the entry was deleted.I'll also note that theRange
docs say that it's safe to modify the map during range; does this apply to deletion?Edit: I can answer my own last question here; this test seems to spell out pretty clearly that delete while ranging is fine.
The text was updated successfully, but these errors were encountered: