flat assembler
Message board for the users of flat assembler.

Index > Main > Need help with strings arrays,remove not the unique elements

Author
Thread Post new topic Reply to topic
lamar



Joined: 05 Jun 2009
Posts: 16
lamar 05 Jun 2009, 23:11
Hey all,i have small problem.
I writting small easy PE importing library in delphi and i am faced with problem.
I need to remove all non-unique elements in an array of strings, leaving only the unique. There is a simple solution, but requires additional memory. I do not like it unnecessarily i like a little code.

Code:
 Memo1.Clear;
 //In randomly order for test
 Memo1.Lines.Add('kernel32.dll,ExitProcess');
 Memo1.Lines.Add('user32.dll,FindWindowA');
 Memo1.Lines.Add('kernel32.dll,Beep');
 //There i sort it
 //...
 Memo2.Clear;
 for I:=0 to Memo1.Lines.Count-1 do
 begin
  if StringExists(Memo2.Lines,Memo1.Lines.Strings[I])=false then Memo2.Lines.Add(Memo1.Lines.Strings[I]);
 end;
    

I also tried a slightly different:
Code:
function Importer_CalculateSize(RealSize:Boolean):Dword; //if RealSize=false then return CountDlls*SizeOf(TImageImportDescriptor)+SizeOf(TImageImportDescriptor)
var
 I,CurrentDllIndex : Dword;
begin
 Result:=SizeOf(TImageImportDescriptor);
 CurrentDllIndex:=0;
 Importer_Sort;
 for I:=0 to ItemsCount-1 do if lstrcmp(PImportItem(Ptr(Dword(Items)+CurrentDllIndex*SizeOf(TImportItem)))^.LibraryName,PImportItem(Ptr(Dword(Items)+I*SizeOf(TImportItem)))^.LibraryName)<>0 then
 begin
  if I+1>MaxItems then CurrentDllIndex:=I else CurrentDllIndex:=I+1;
  Inc(Result,SizeOf(TImageImportDescriptor));
 end;
end;    

HAAALP Surprised
Post 05 Jun 2009, 23:11
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4039
Location: vpcmpistri
bitRAKE 06 Jun 2009, 00:47
It's customary to only add items to an array if they are not already there - hashing is ideal for this.
Post 06 Jun 2009, 00:47
View user's profile Send private message Visit poster's website Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville 06 Jun 2009, 20:25
I never heard of for...do, begin, if, end instructions in x86 assembler.
Lamar, did you write some macros for these ? Wink

_________________
FAMOS - the first memory operating system
Post 06 Jun 2009, 20:25
View user's profile Send private message Visit poster's website Reply with quote
lamar



Joined: 05 Jun 2009
Posts: 16
lamar 06 Jun 2009, 22:34
More none no ideas except as hasing ?
Code:
 ...
 mov [ebp-4],0 ;I var
 mov [ebp-8],10;ItemsCount-1
@Cycle 
...do something
 inc [ebp-4]
 mov eax,[ebp-8]
 cmp [ebp-4],eax
 jl @Cycle
    
Post 06 Jun 2009, 22:34
View user's profile Send private message Reply with quote
lamar



Joined: 05 Jun 2009
Posts: 16
lamar 07 Jun 2009, 02:48
bitBRAKE,hashing good for a compiler to hash function names and strings,but not for me.
Problem solved huh Laughing
Post 07 Jun 2009, 02:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.