Handbook
Glossary
encode-numbers ( sqids numbers increment -- str )
Vocabulary
sqids
.
private
Inputs
sqids
an
object
numbers
an
object
increment
an
object
Outputs
str
an
object
Definition
USING:
accessors
kernel
math
sbufs
sequences
sqids
strings
;
IN:
sqids.private
::
encode-numbers
( sqids numbers increment -- str )
sqids
alphabet>>
:>
alphabet alphabet
length
:>
len
increment len
>
[
max-attempts-reached
]
when
numbers alphabet
starting-offset
increment
+
len
mod
:>
offset alphabet offset
cut
swap
append
:>
rotated rotated
first
1string
>sbuf
:>
sbuf sbuf rotated
reverse
numbers
write-numbers
:>
shuffled sbuf shuffled sqids
min-length>>
pad-to-min-length
sbuf
>string
dup
sqids
blocked-id?
[
drop
sqids numbers increment 1
+
encode-numbers
]
when
;