retroforth/interface/dedup.retro
crc 3eec5480ab make some small optimizations to some fll: words
FossilOrigin-Name: 767c0b08d5e9ddd854a15027d025aa1b89f5359c67718b0bf51e2a06c2996f71
2023-10-23 16:08:18 +00:00

28 lines
586 B
Forth

# s:dedup
String deduplication for RetroForth.
(c) Arland Childers
~~~
'init s:keep fll:create 's:dedup.data var-n
{{
't1 var
't2 var
---reveal---
:s:dedup.register (s-)
s:keep @s:dedup.data swap &fll:append/value sip ;
:s:dedup.defined? (s-f)
!t1 #0 !t2
@s:dedup.data [ @t1 s:eq? @t2 or !t2 ] fll:for-each @t2 ;
:s:dedup.find (s-s)
!t1 #0 !t2
@s:dedup.data [ dup @t1 s:eq? [ !t2 ] &drop choose ]
fll:for-each @t2 ;
:s:dedup (s-s)
dup s:dedup.defined? &s:dedup.find &s:dedup.register
choose ;
:s:unique? (s-f) s:dedup.defined? ;
}}
~~~