Random question, but how do we do equality for a List U8?
If I have a large List U8 and then take lots of smaller sublists, is it super efficient to compare these smaller List U8's against each other if I pass them into functions etc? I guess I'm asking if these would be just a comparison of the slice or reference, or is it something deeper?
Would it be inefficient to use a List U8 as a key to a Dict?
Or could I use something like Box (List U8) if I want it to be a reference?
dicts use a hash, which means the whole list is traversed. That might be a problem for very large lists
really depends on the specifics how good/bad of an idea this is
I'm thinking of a use case when decoding JSON, of using a List U8 input bytes as an index into another data structure.
I feel like if the List U8 is actually stored on the heap and is only a reference, then equality may be very fast.
well yes but not with hashing.
for equality we first compare the lengths, then the pointers, and if the pointers are not the same we compare elements
but a hash will always look at all the elements
If I have a record such as {field : List U8, value : List U8}
and the List U8
are slices from another larger List U8
is this record a fixed size? I guess I am concerned that putting these lists in record fields will make unnecessary allocations.
The record is always fixed sized, the data being allocation free depends on how you use it
If they are always referencing a larger list and never edited, they would be seamless slices and never allocate
Thanks Brendan that makes sense
Last updated: Jul 06 2025 at 12:14 UTC