https://gitlab.com/tezos/tezos
Raw File
Tip revision: 71508a86c7784e0a76dc60dac44fd1e252500665 authored by vbot on 25 August 2023, 13:05:49 UTC
yes-node
Tip revision: 71508a8
queue.tz
parameter (option string);
storage (pair (option string) (pair (pair nat nat) (map nat string)));
code { DUP; CAR;
       # Retrieving an element
       IF_NONE { CDDR; DUP; CAR; DIP{CDR; DUP}; DUP;
                 CAR; SWAP; DIP{GET}; # Check if an element is available
                 SWAP;
                 # Put NONE on stack and finish
                 IF_NONE { NONE string; DIP{PAIR}; PAIR}
                         # Reoption the element and remove the entry from the map
                         { SOME;
                           DIP{ DUP; DIP{ CAR; DIP{ NONE string }; UPDATE };
                                # Increment the counter and cleanup
                                DUP; CAR; PUSH nat 1; ADD; DIP{ CDR }; PAIR; PAIR};
                           PAIR }}
               # Arrange the stack
               { DIP{DUP; CDDAR; DIP{CDDDR}; DUP}; SWAP; CAR;
                 # Add the element to the map
                 DIP{ SOME; SWAP; CDR; DUP; DIP{UPDATE};
                      # Increment the second number
                      PUSH nat 1; ADD};
                 # Cleanup and finish
                 PAIR; PAIR; NONE string; PAIR };
       NIL operation; PAIR}
back to top