Best Implementation for Set of Elements that I manually change

New to FreeBASIC? Post your questions here.
Lost Zergling
Posts: 260
Joined: Dec 02, 2011 22:51
Location: France

Re: Best Implementation for Set of Elements that I manually change

Postby Lost Zergling » May 23, 2019 13:04

Hi JohnM
This one is not the best implementation (your specifications does ot need keys, just indices)
Much slower(*), consummes memory and requires a library (viewtopic.php?f=8&t=26533), BETA state.
Depending on what you expect to do you might appreciate using it (if only for 'short' syntax).
(on previous versions of the compiler, I could load bigger string if string type not in an array when loading lots of strings)
(*) : In most of user cases user will not notice.

Code: Select all

#Include once "D:\Basic\"
Dim MyList As List
Dim As String file_name, text, StrNumLigne
Dim As Integer file_num, indice=0

file_name = "D:\Basic\Filename.ext"
file_num = FreeFile( )
If( Open( file_name For Input As #file_num ) ) Then
   Print file_name & " not opened"
   Do Until EOF( file_num )               '' loop until we have reached the end of the file     
      Line Input #file_num, text               '' read a line of text ...
      MyList.HashTag(Str(indice)) : MyList.Val(text)
   Close #file_num
End If
Randomize , 1
StrNumLigne=Str(Int(Rnd * indice))
MyList.HashTag( StrNumLigne )
Print "Line " & StrNumLigne & " = " & MyList.Val

To substract an element, syntax is :

Code: Select all

'Persistent parameters (need to be set one time)
MyList.NFRecursive(1) 'Optional : forces dynamic reuse of obsolete index entries (automatic only when NodeFlat is in a loop)
MyList.NFmethod(-1) 'Indicates destination for NodeFlat (GarbageCollector)

'For each element you want to delete/substract
MyList.HashTag( ValidKey ) : MyList.NodeFlat 'If key is not valid a empty element will be created then send to "GarbageCollector"
' Or
If MyList.HasKey( ValidKey ? ) Then : MyList.NodeFlat : End If  ' (slower) (Check NFmethod and AutoCursor)

This should handle heavy memory load in a context you're adding and substracting a lot of elements when processing.

PS : Welcome to FreeBasic :-)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest