PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: hash map wanted  (Read 765 times)

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 41
  • FF3 User
hash map wanted
« on: December 22, 2017, 01:22:08 PM »

I would like to have reliable hashmap for FreeBasic but I am not competent enough to write it, anyone interested in doing it?
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8366
  • Windows 10
    • PlanetSquires Software
Re: hash map wanted
« Reply #1 on: December 22, 2017, 02:00:56 PM »

Try using Jose's WinFBX library. Look at the Dictionary Class (CDicObj.inc). Read the WinFBX help file for usage details. This class should save to a lot of time and effort.

Code: [Select]
' CDicObj is an associative array of variants. Each item is associated with a unique key. The key is used to retrieve an individual item.

'Example

#define unicode
#INCLUDE ONCE "Afx/CDicObj.inc"
USING Afx

' // Creates an instance of the CDicObj class
DIM pDic AS CDicObj

' // Adds some key, value pairs
pDic.Add "a", "Athens"
pDic.Add "b", "Belgrade"
pDic.Add "c", "Cairo"

print "Count: "; pDic.Count
print pDic.Exists("a")
print

' // Retrieve an item and display it
print pDic.Item("b")
print

' // Change key "b" to "m" and "Belgrade" to "México"
pDic.Key("b") = "m"
pDic.Item("m") = "México"
print pDic.Item("m")
print

' // Get all the items and display them
DIM cvItems AS CVAR = pDic.Items
FOR i AS LONG = cvItems.GetLBound TO cvItems.GetUBound
  print cvItems.GetVariantElem(i)
NEXT

print

' // Get all the keys and display them
DIM cvKeys AS CVAR = pDic.Keys
FOR i AS LONG = cvKeys.GetLBound TO cvKeys.GetUBound
  print cvKeys.GetVariantElem(i)
NEXT

print

' // Remove key "m"
pDic.Remove "m"
IF pDic.Exists("m") THEN PRINT "Key m exists" ELSE PRINT "Key m doesn't exists"

' // Remove all keys
pDic.RemoveAll
print "All the keys must have been deleted"
print "Count: "; pDic.Count

PRINT

PRINT "Press any key..."

SLEEP
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Johan Klassen

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 41
  • FF3 User
Re: hash map wanted
« Reply #2 on: December 22, 2017, 05:11:18 PM »

thank you Paul :)
I was not aware that Jose Roca had already done the implementation.
Logged