Skip to content

Commit

Permalink
FEAT: deduplicate mezzanine (modifying unique)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 30, 2020
1 parent e29b737 commit 4e47595
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/mezz/mezz-series.r
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ extract: func [
either into [output] [head output]
]

deduplicate: func [
"Removes duplicates from the data set."
set [block! string! binary!] "The data set (modified)"
/case "Use case-sensitive comparison"
/skip "Treat the series as records of fixed size"
size [integer!]
] [
head insert set also apply :unique [set case skip size] clear set
]

alter: func [
"Append value if not found, else remove it; returns true if added."
series [series! port! bitset!] {(modified)}
Expand Down
29 changes: 24 additions & 5 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ Rebol [
===end-group===


===start-group=== "BLOCK"
===start-group=== "BINARY"

--test-- "CHANGE binary! integer!"
;@@ https://github.com/Oldes/Rebol-issues/issues/966
Expand Down Expand Up @@ -566,7 +566,7 @@ Rebol [
===end-group===


===start-group=== "BINARY"
===start-group=== "BLOCK"

--test-- "path in block"
;@@ https://github.com/Oldes/Rebol-issues/issues/26
Expand All @@ -584,18 +584,37 @@ Rebol [

===end-group===

===start-group=== "UNIQUE"
===start-group=== "UNIQUE & DEDUPLICATE"

--test-- "unique on string"
;@@ https://github.com/Oldes/Rebol-issues/issues/402
--assert "123" = unique "123"
--assert "123" = unique "123123"
--assert "123" = unique s: "123123"
--assert s = "123123" ;- unique does not modify its input
--assert "123" = deduplicate s: "123123" ;- while deduplicate does
--assert "123" = s ;- https://github.com/Oldes/Rebol-issues/issues/1573
--test-- "unique/skip on string"
--assert "abca" = unique/skip "ababca" 2
--assert "ababca" = unique/skip "ababca" 3
--assert "ababca" = unique/skip s: "ababcaaba" 3
--assert s = "ababcaaba"
--assert "ababca" = deduplicate/skip s: "ababcaaba" 3
--assert "ababca" = s

--test-- "unique on block"
--assert [1 2] = unique [1 2]
--assert [1 2] = unique b: [1 2 2 1]
--assert b = [1 2 2 1] ;- unique does not modify its input
--assert [1 2] = deduplicate b: [1 2 2 1]
--assert [1 2] = b ;- while deduplicate does
--test-- "unique/skip on block"
--assert [1 2 3 4] = unique/skip b: [1 2 1 2 3 4] 2
--assert b = [1 2 1 2 3 4]
--assert [1 2 3 4] = deduplicate/skip b: [1 2 1 2 3 4] 2
--assert [1 2 3 4] = b

===end-group===


;-- VECTOR related tests moved to %vector-test.r3

~~~end-file~~~

0 comments on commit 4e47595

Please sign in to comment.