The mathematical structure of a set is an unordered collection. If a set does not have an order, how are they serialized by the PACK
instruction?
According to this overview set
is packable.
Tezos Stack Exchange is a question and answer site for users, experts, and developers of the Tezos blockchain project. It only takes a minute to sign up.
Sign up to join this communityThe mathematical structure of a set is an unordered collection. If a set does not have an order, how are they serialized by the PACK
instruction?
According to this overview set
is packable.
Sets are serialized by first ordering the elements, and then packing them as a sequence which is also how lists are represented when PACK
is called. This means that these two expressions evaluate to the same, since they are first sorted, and then serialized.
ligo interpret -s pascaligo 'Bytes.pack(set [ 1; 2; 3; 4 ])'
ligo interpret -s pascaligo 'Bytes.pack(set [ 4; 2; 3; 1 ])'
Both output the same byte array
0x0502000000080001000200030004
Where
05
is the prefix for any output from the PACK
instruction02
is the tag for the sequence type00000008
is the four bytes indicating the size of the coming values, in bytes0001000200030004
are then numbers 1,2,3,4
encoded with first a 00
tag to indicate that this is a integer, and the numbers 01
, ... 04
are the encoding of the actual numbers.PUSH (set nat) { 1 ; 3 ; 2 };
does not typecheck, where as PUSH (set nat) { 1 ; 2 ; 3 };
does.
Comparable
has an order. The ordering of integers is there numerical order, the ordering of strings and addresses is alphabetical ordering. Cf michelson.nomadic-labs.com/#instr-COMPARE
Oct 16, 2020 at 13:47