core icon indicating copy to clipboard operation
core copied to clipboard

Is it necessary to implement hash/compare trait and for Array?

Open Lampese opened this issue 1 year ago • 3 comments

  • [x] Compare (done in #1003)
  • [ ] Hash (to be discuss)

Lampese avatar Aug 29 '24 16:08 Lampese

compare is needed, not sure about hash though

bobzhang avatar Sep 10 '24 01:09 bobzhang

use case for hash: BPE tokenizer. In BPE tokenizer I need to maintain a Map[(Array[Int], Array[Int]), Array[Int]] when merging multi-byte pairs.

tonyfettes avatar Sep 11 '24 09:09 tonyfettes

I strongly against to add compare and hash to mutable collection types. If it's needed, we can provide Iter::compare and Iter::hash as workaround.

It's another question that should we provide ReadonlyArray?

hackwaly avatar Oct 09 '24 09:10 hackwaly

I have another use case: hash cons when compiling a computation graph.

The const in a computation graph is a FixedArray[Float] (or Array[Float]) and I need it to be hashable so that I can derive Hash for my graph data type.

tonyfettes avatar Dec 27 '24 02:12 tonyfettes

I agree we should add hash for Array, user can always misuse HashMap if they want

bobzhang avatar Apr 06 '25 03:04 bobzhang