Skiplist duplicate items removal

Hello All,

I have a skiplist , which stores integer as a key and the value will be some attribute name. I am using this skip list to convert to an array and then populate a drop down dynamically.

I found in some forum threads , using string as a key in skip list, will automatically identify the duplicate elements.

But is there any way to find and remove duplicate values in skiplist with int key values using dxl?

Any kind of help is appreciated.

Thanks ,

Anish

 

 


Adminani - Tue Jan 27 03:52:19 EST 2015

Re: Skiplist duplicate items removal
Mike.Scharnow - Tue Jan 27 06:01:28 EST 2015

There are several ways to remove duplicate data.

Probably the fastest way would be a second skip list.

Skip skOriginal = create() ; ... fill skOriginal ....; // key: int, data: string
string strVal
Skip skHelper = createString() // key: string, data: int
for strVal in skOriginal do {
    int iKey = (key skOriginal) int
    put (skHelper, strVal, iKey) // will fail when strVal key is already in Skip list
}
delete skOriginal
skOriginal = create()
int iVal
for iVal in skHelper do {
    string strKey = (key skHelper) string
    put (skOriginal, iVal, strKey)
}
delete skHelper

 

Re: Skiplist duplicate items removal
Wolfgang Uhr - Tue Jan 27 07:33:56 EST 2015

void removeDuplicates(Skip skpWork) {
    Skip skpHelp = createString();
 string sNumber;
 for sNumber in skpWork do {
  if (find(skpHelp, sNumber)) {
   int iID = (int key(skpWork));
   delete(skpWork, iID);
  } else {
   put(skpHelp, sNumber, sNumber);
  }
 }
}

Skip skpWork = create();
put (skpWork, 1, "eins");
put (skpWork, 2, "zwei");
put (skpWork, 3, "drei");
put (skpWork, 4, "eins");

removeDuplicates(skpWork);

string sNumber;
for sNumber in skpWork do {
 print sNumber "\n";
}

 

Re: Skiplist duplicate items removal
Adminani - Wed Jan 28 04:13:42 EST 2015

Wolfgang Uhr - Tue Jan 27 07:33:56 EST 2015

void removeDuplicates(Skip skpWork) {
    Skip skpHelp = createString();
 string sNumber;
 for sNumber in skpWork do {
  if (find(skpHelp, sNumber)) {
   int iID = (int key(skpWork));
   delete(skpWork, iID);
  } else {
   put(skpHelp, sNumber, sNumber);
  }
 }
}

Skip skpWork = create();
put (skpWork, 1, "eins");
put (skpWork, 2, "zwei");
put (skpWork, 3, "drei");
put (skpWork, 4, "eins");

removeDuplicates(skpWork);

string sNumber;
for sNumber in skpWork do {
 print sNumber "\n";
}

 

Thanks a lot..!!!:)

It worked!!!:):)