a concise shot of dev knowledge
Become a Contributor
Concise shots of dev knowledge

RELATED TAGS

euphoria
communitycreator

What is the remove_dups() method in Euphoria?

NDUKWE CHIDERA K.

Overview

The remove_dups() method is part of the e.sequence, a standard Euphoria library module. It performs a basic operations on sequence variables.

The remove_dups() function loops through a sequence and returns values from such a sequence. It does this by checking for a duplicate value in such a sequence and returns only one of such values. This returned sequence value has a different sort arrangement, which we can specify using the proc_option parameter.

Syntax

remove_dups(source_data,proc_option)

Parameters

  • source_data: This is the sequence variable from which we want to remove duplicate elements.

  • proc_option: This integer value indicates the routine_id of the duplicate removal option you want. The procedure called by the routine_id will determine what type of sorting will be performed on the returned sequence.

Note: The proc_option parameter is only a name that can be one of RD_INPLACE, RD_PRESORTED, or RD_SORT. It is evaluated to an integer called a routine_id.

The proc_option options

  • RD_INPLACE: This option removes duplicate items with the original order of unique items preserved.

  • RD_PRESORTED: With this option, there is an assumption that the items of source_data are already sorted. If this assumption proves false, the only removed duplicates are the values side-by-side, adjacent duplicate items.

  • RD_SORT: This checks for unique values throughout the sequence and returns only the unique values sorted in ascending order.

Return value

This function will return a sequence with unique values sorted in an order as indicated.

Example

include std/sequence.e

sequence seq = { 3,6,5,6,2,7,5,5,0,3,3,5,6,7}
sequence result1 = remove_dups(seq, RD_INPLACE)
sequence result2 = remove_dups(seq, RD_SORT) 
sequence result3 = remove_dups(seq, RD_PRESORTED)
sequence result4 = remove_dups(seq, RD_PRESORTED) 

print(1,result1)
puts(1,"\n")
print(1,result2)
puts(1,"\n")
print(1,result3)
puts(1,"\n")
print(1,result4)

Explanation

  • Line 1: We include the sequence.e module to access the method.
  • Line 3: We declare a variable to contain our sequence.
  • Lines 4–7: We use the remove_dups() method.
  • Lines 9–15: We print the sequences with duplicates removed to the screen.

RELATED TAGS

euphoria
communitycreator
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time

Copyright ©2022 Educative, Inc. All rights reserved.

soc2