Closed iand closed 1 year ago
In order to remove the errors returned from KadKey
methods, we can simply accept any size of key, and move the responsibility to check the key size to the caller.
When an method is called on 2 keys of different size, consider that the shorter one is a prefix (aligned left). Just like if we pad right zeros to the shortest key.
Equal
would return true
iff the keysize is the same for both keys, and all bits are the sameCompare
with 2 different key sizes would compare the bits of the 2 keys up to the size of the shortest key. If key0[:shortestKeyLen]==key1[:shortestKeyLen]
, consider that shortest_key < longest_key
. Return 0
iff key0.Equal(key1)
.CommonPrefixLength
returns the actual CPL (given that the shortest key is a prefix, and not a suffix), so CPL <= shortestKeyLen
Xor
normally xors longestKey
and shortestKey+"00"*(longestKeyLen-shortestKeyLen)
. So the last bits of longestKey
stay unchanged
When https://github.com/golang/go/issues/44253 is implemented we could replace
any
by[...]byte