Softanza
DémarrerEnglish
Softanza
Recherche · narration

Decoding Duplicates: Exploring Duplicate Detection and Removal with Softanza

Let’s dive into an engaging exploration of how Softanza handles duplicate detection and management in strings. Consider this illustrative string:

par Mansour Ayouni · dans le dépôt depuis le 2024-12-11 · essai de fonction · domaine Chaînes de caractères

Cet article est écrit en anglais, comme la bibliothèque.

Manging Duplicates in Softanza, by Microsoft Image Create AI
Manging Duplicates in Softanza, by Microsoft Image Create AI

Manging Duplicates in Softanza, by Microsoft Image Create AI


First, let's load the library and create a stzString object:

Haro
load "stzlib.ring"

o1 = new stzString("ABRACADABRA")

illustration

The Question: Are there any duplicated substrings?

The ContainsDuplicates() function reveals the presence of duplicates:

Haro
? o1.ContainsDuplicates()
#--> TRUE

exécuté le 2026-10-08 20:44 au commit 4a184e6f0 : a tenu sa promesse

Yes, duplicates are present.

Counting the Duplicates

How many duplicates are there?

Haro
? o1.CountDuplicates()
#--> 6

illustration

There are 6 duplicates.

Locating the Duplicates

We locate their positions using FindDuplicates():

Haro
? @@( o1.FindDuplicates() )
#--> [ 0, 3, 7, 8, 9 ]

illustration

The duplicates occur across 5 unique positions.

Identifying the Duplicates

The Duplicates() function shows which substrings are duplicated:

Haro
? @@( o1.Duplicates() )
#--> [ "A", "AB", "B", "R", "A" ]

illustration

Here are all six duplicated substrings, including overlaps.

Understanding Overlapping Duplicates

Using DuplicatesZ() provides insights into overlapping duplicates and their positions:

Haro
? @@( o1.DuplicatesZ() )
#--> [ ["A", 0], ["AB", 0], ["B", 1], ["R", 3], ["A", 7] ]

illustration

At position 0, two substrings ("A" and "AB") overlap, explaining the count mismatch.

Removing the Duplicates

Finally, we simplify the string by removing duplicates:

Haro
o1.RemoveDuplicates()
? o1.Content()
#--> "ABRCAD"

illustration

>NOTE: In Softanza, as a general principle, anything that works for strings will work the same way for lists, following the same syntax and semantics. You can test this yourself by simply replacing o1 = new stzString("ABRACADABRA") by o1 = new stzList([ "A", "B", "R", "A", "C", "A", "D", "A", "B", "R", "A" ]) and making no other changes in your code!

Conclusion

This exploration demonstrates the power of the Softanza library's string manipulation capabilities. By identifying, analyzing, and ultimately removing duplicates, we transform a verbose string into its most concise form. This functionality is invaluable in applications ranging from text processing to data compression, offering both efficiency and clarity in handling complex string data.

Lectures liées

Citer

Mansour Ayouni. « Decoding Duplicates: Exploring Duplicate Detection and Removal with Softanza ». Softanza narrations, 2024. https://mayouni.github.io/stzsite/fr/narrations/stzstring-duplicates-narration.html

Exécuté au nom de Haro le 2026-10-08 20:44 dans la bibliothèque au commit 4a184e6f0, bloc après bloc dans un seul processus : 1 bloc(s) sur 7 ont tenu leur promesse ; les autres sont des illustrations. Le code des articles est du code Haro. Là où un article a été écrit avant que la langue prenne son nom actuel, le nom a été changé et rien d'autre. Genre, domaine et série lus dans le nom du fichier, année tirée du premier commit : dérivés, jusqu'à ce que l'article porte son propre en-tête. Le fichier sur GitHub(s'ouvre dans un nouvel onglet)