Recent

Author Topic: Removing duplicates from an array  (Read 4925 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: Removing duplicates from an array
« Reply #30 on: June 06, 2022, 09:01:54 pm »
I am never bloating. You can't read. And where appropiate I always provide a compilable example.
IOW you are fired! in the unlikely case you ever worked for me. I know a rat compared to a rabbit.

Shut this.
« Last Edit: June 06, 2022, 09:04:48 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Removing duplicates from an array
« Reply #31 on: June 07, 2022, 11:41:15 am »
Turning them into indexed hashes and sorting those sounds good to me. Depending on how you sort, comparing them is often the thing that takes the most time and with hashes you only have to read the data once.
Then again, if the entries are long sentences, finding the first difference might be faster. I can think of edge cases either way.

Joanna

  • Hero Member
  • *****
  • Posts: 770
Re: Removing duplicates from an array
« Reply #32 on: June 16, 2022, 03:27:49 am »
I understand that knowing how to remove duplicates from an array has academic merit but in real life programming wouldn’t it be better to work on the problem of duplicate values getting into the array to begin with? It seems like no matter what you do it’s going to take a lot of extra time and effort to undo the duplicates in array.
Has there ever been considered an Function indexof(Avalue) to detect duplicates of an array or maybe a flag to not allow duplicates? If seen this for various other things so it seems like it should be possible to implement them for arrays.
« Last Edit: August 04, 2023, 06:29:02 pm by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 50
Re: Removing duplicates from an array
« Reply #33 on: August 01, 2022, 12:17:06 am »
Code: Text  [Select][+][-]
  1. Wow,
  2.  Hash tables, Log n ( time analysis), collections, helpers, generics, sorting procedures...
  3. You guys are way over my level of ability. Nevertheless; here is how I would detect and
  4. eliminate duplicates in an array and YES; my way is probably inefficient in both memory
  5. and processor utilization, but it is just my way.
  6.  
  7. =============pseudo code=================
  8. var
  9.   Array_dups[0..9] of integer=[8,6,9,11,6,22,3,8,6];
  10.   Array_Fixed[0..9999] of integer; {Declare *expected* max range}
  11.   x:integer;
  12.  
  13. Begin
  14.    Initialize_All_Elements_to_Zero (array_Fixed);
  15.    for x:=0 to High(Array_Dups) Do
  16.      Array_Fixed[Array_Dups[x]]
  17.            :=  Array_Fixed[Array_Dups[x]]+1;
  18.  
  19. //////////////////////////////////////////////////////////////////////////////
  20.  At this point the elements of Array_fixed indicate the following
  21.          all elements  =0 did not occur in Array_Dups
  22.          all elements  =1 occurred only once in Array_Dups
  23.          all elements  >1 had duplicates in Array_Dups
  24.  
  25. It is now trivial to assign the values of Array_Fixed back into
  26. Array_Dups or manipulate or assign them in any manner that you choose
  27.  
  28.  
« Last Edit: August 01, 2022, 12:24:06 am by Ten_Mile_Hike »

 

TinyPortal © 2005-2018