It is currently Fri Jan 15, 2021 4:11 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: PureDIC library : associative array / dictionary
PostPosted: Wed Feb 27, 2008 8:56 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
PureDIC library

Overview
Code:
This is a purebasic associative array / dictionary library using some GDSL hash table functions.

Find more information about GDSL at http://directory.fsf.org/all/GDSL.html

An associative array is an abstract data type composed of a collection of keys and a collection of values, where each key is associated with one value. The operation of finding the value associated with a key is called a lookup or indexing, and this is the most important operation supported by an associative array. The relationship between a key and its value is sometimes called a mapping or binding. For example, if the value associated with the key "bob" is 7, we say that our array maps "bob" to 7.

Functions
PB4.xx : http://gnozal.ucoz.com/PureDIC_.htm

Example
Code:
; Parsing callback - IMPORTANT : it MUST be a ProcedureC() !!!
ProcedureC ParseCB(*HTEObject.HTElement, NotUsed.l, *uData.HTInfo)
  Protected StringKey.s, Value.l, UserValue.l, *HashTable
  ;
  *HashTable = *uData\HT
  StringKey = PeekS(*HTEObject\key)
  Value = *HTEObject\uData
  UserValue = *HTEObject\uData
  ;
  Debug Str(*HashTable) + " -> '" + StringKey + "' : " + Str(Value) + " [" + Str(UserValue) + "]"
  ;
  ; Use #GDSL_MAP_STOP : if the parsing must be stopped
  ; Use #GDSL_MAP_CONT : if the parsing must continue
  ;
  ProcedureReturn #GDSL_MAP_CONT
EndProcedure
;

; Create new dictionary
*HashTable = PureDIC_Create()
If *HashTable
 
  Debug "Dictionary created, handle = " + Str(*HashTable)
 
  ; Add random elements
  For i = 0 To 200
    a$ = Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255))
    ;
    PureDIC_Add(*HashTable, a$, i)
    ;
    If i = 100
      b$ = a$
    EndIf
    If i = 150
      c$ = a$
    EndIf
   
  Next
 
  ; Count elements in dictionnary
  Debug "Count = " + Str(PureDIC_Count(*HashTable))
 
  ; Parse elements in dictionnary
  Debug "PARSE table"
  PureDIC_Parse(*HashTable, @ParseCB())
  Debug "END Parse"
 
  ; Get the 100th added element
  Debug "Expected is 100 -> " + Str(PureDIC_Get(*HashTable, b$))
 
 
  ; Get the 150th added element
  Debug "Expected is 150 -> " + Str(PureDIC_Get(*HashTable, c$))
 
  ; See if elements exists
  d$ = "------"
  Debug "Expected is 0 -> " + Str(PureDIC_Exist(*HashTable,d$))
  Debug "Expected is 1 -> " + Str(PureDIC_Exist(*HashTable,c$))
 
  ; Close dictionary
  PureDIC_Close(*HashTable)
 
EndIf


Download
Only available for Purebasic Windows x86
PB4.0x-4.20 : http://gnozal.ucoz.com/PureDIC_.zip
PB4.3x : http://gnozal.ucoz.com/PureDIC_430.zip
PB4.4x : http://gnozal.ucoz.com/PureDIC_440.zip
PB4.5x : http://gnozal.ucoz.com/PureDIC_450.zip
PB4.6x : http://gnozal.ucoz.com/PureDIC_460.zip
PB5.0x : http://gnozal.ucoz.com/PureDIC_500.zip

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Last edited by gnozal on Tue Aug 18, 2009 11:51 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Getting a linking error
PostPosted: Tue Aug 11, 2009 3:03 pm 
Offline
User
User
User avatar

Joined: Sat Sep 30, 2006 11:36 pm
Posts: 29
Location: Atlanta, Georgia
Hi Gnozal,

I'm using 4.31 on Windows XP and I'm getting a linking error. I've installed Pure_DIC 4.30.

The error is:
Quote:
POLINK: error: Unresolved external symbol '_PB_StringBasePosition'
POLINK: fatal error: 1 unresolved external(s).


Any ideas as to what I'm doing wrong? I've tried the example program, the one in the help file, and even just a one line *test = PureDic_Create().

Thanks,

Randy

_________________
Maybe it's just a bunch of stuff that happens -- Homer Simpson


Top
 Profile  
Reply with quote  
 Post subject: Re: Getting a linking error
PostPosted: Tue Aug 11, 2009 3:30 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
Hi Randy,
Randy wrote:
The error is:
Quote:
POLINK: error: Unresolved external symbol '_PB_StringBasePosition'
POLINK: fatal error: 1 unresolved external(s).
You have probably unicode and/or threasafe enabled.
- threadsafe : you need to activate the appropriate subsytem ; have a look at the help file PureDIC.chm ('threadsafe' topic).
- unicode : not supported (I didn't need it) ; you may add the unicode support yourself (see the included sources).

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
Reply with quote  
 Post subject: It was the threadsafe option
PostPosted: Tue Aug 11, 2009 3:44 pm 
Offline
User
User
User avatar

Joined: Sat Sep 30, 2006 11:36 pm
Posts: 29
Location: Atlanta, Georgia
I didn't realize I had the thing checked nor that it was even an option. :oops: Anyway, all is well. Thanks for the quick response!

Randy

_________________
Maybe it's just a bunch of stuff that happens -- Homer Simpson


Top
 Profile  
Reply with quote  
 Post subject: Clearing The Table
PostPosted: Thu Aug 13, 2009 5:53 pm 
Offline
User
User
User avatar

Joined: Sat Sep 30, 2006 11:36 pm
Posts: 29
Location: Atlanta, Georgia
Hi again Gnozal,

If you decide to work or enhance this library, would it be possible to add something to clear the table? Right now I'm closing and reopening which works. It's just that I thought it would be a neater solution to have something like PureDIC_Clear(*HashTable).

Thanks,

Randy

_________________
Maybe it's just a bunch of stuff that happens -- Homer Simpson


Top
 Profile  
Reply with quote  
 Post subject: Re: Clearing The Table
PostPosted: Fri Aug 14, 2009 1:36 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
Randy wrote:
If you decide to work or enhance this library, would it be possible to add something to clear the table? Right now I'm closing and reopening which works. It's just that I thought it would be a neater solution to have something like PureDIC_Clear(*HashTable).

Just add this to your code :
Code:
ImportC ""
  gdsl_hash_flush(*HashTable)
EndImport
Procedure PureDIC_Clear(*HashTable) ; Clear hashtable
  ProcedureReturn gdsl_hash_flush(*HashTable)
EndProcedure


Also note that PB4.40 now has a genuine hash table library (Map) : http://www.purebasic.fr/english/viewtopic.php?t=38503

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
Reply with quote  
 Post subject: I noticed
PostPosted: Fri Aug 14, 2009 2:50 pm 
Offline
User
User
User avatar

Joined: Sat Sep 30, 2006 11:36 pm
Posts: 29
Location: Atlanta, Georgia
Thanks Gnozal,

It was a little while later that I spotted the beta version and downloaded it. The internal map system seems to work so far and had this request inside it.

I don't know when 4.40 becomes final so I'm keeping it and 4.31 just in case. Since 4.31 doesn't have mapping, your routines are still in place so this will help.

Thanks again,

Randy

_________________
Maybe it's just a bunch of stuff that happens -- Homer Simpson


Top
 Profile  
Reply with quote  
 Post subject: Re: Clearing The Table
PostPosted: Wed Dec 03, 2014 8:13 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2337
Location: Singapore
A curious case of deja vu! :lol:

(on Fri Aug 14, 2009)
Randy wrote:
If you decide to work or enhance this library, would it be possible to add something to clear the table? Right now I'm closing and reopening which works. It's just that I thought it would be a neater solution to have something like PureDIC_Clear(*HashTable).

(on Wed Dec 03, 2014)
maya112 wrote:
If you decide to work or enhance this library, would it be possible to add something to clear the table? Right now I'm closing and reopening which works. It's just that I thought it would be a neater solution to have something like PureDIC_Clear(*HashTable).


@maya112 (if you're not a figment of my imagination, as your name suggests), gnozal had already posted the solution:
gnozal wrote:
Just add this to your code :
Code:
ImportC ""
  gdsl_hash_flush(*HashTable)
EndImport
Procedure PureDIC_Clear(*HashTable) ; Clear hashtable
  ProcedureReturn gdsl_hash_flush(*HashTable)
EndProcedure

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: PureDIC library : associative array / dictionary
PostPosted: Wed Dec 03, 2014 8:14 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6271
Location: Wales, UK
or perhaps a spammer easing some posts in before an attack?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye