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


  • Hero Member
  • *****
  • Posts: 12210
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 »
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.


  • Hero Member
  • *****
  • Posts: 1136
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.


  • Full Member
  • ***
  • Posts: 150
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.

Also Jamie can you please bring your expertise back to Irc ? We need more experts there.
« Last Edit: June 16, 2022, 03:38:56 am by Joanna »
Come chat on IRC .. IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channels  #fpc #lazarus #pascal 
type /msg nickserv help register to get started


  • New Member
  • *
  • Posts: 13
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.
  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;
  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;
  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
  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
« Last Edit: August 01, 2022, 12:24:06 am by Ten_Mile_Hike »


TinyPortal © 2005-2018