Jump to content

scripting.dictionary in the role of map


iamtheky
 Share

Recommended Posts

That could be tested by assigning the array to null and trying to access the dictionary instance..

EDIT: looks like a copy is made.

$myDictionary = _MapInit()

;map add key/value pairs

_MapAddKeyValuePair($myDictionary , "KeyEntry0" , "ValueEntry0")    ; adding key/value pairs
_MapAddKeyValuePair($myDictionary , "KeyEntry1" , "ValueEntry1")
_MapAddKeyValuePair($myDictionary , "KeyEntry2" , "ValueEntry2")


local $aTestarray[2]
      $aTestarray[0] = "ValueEntry3-1"
      $aTestarray[1] = "ValueEntry3-2"

_MapAddKeyValuePair($myDictionary , "KeyEntry3" , $aTestarray)

$aTestarray = null

For $value in $myDictionary.Item("KeyEntry3")
    consolewrite($value & @LF)
Next

Works just fine.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Is this the best manner in which to unpack a dictionary with both strings and arrays?  I'm thinking now that specifying a duplicate key should give the option to make an array of values rather than fail or append to the string.

For $Key in $myDictionary
   
   If IsArray($myDictionary.Item($Key)) Then
      
      For $value in $myDictionary.Item($Key)
         consolewrite($Key & "=" & $value & @LF)
      Next
      
   Else
      
      consolewrite($key & "=" & $myDictionary.Item($Key) & @LF)
      
   EndIf
Next

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Avoiding a large array copy, you can drop a dictionary in your dictionary...  Creating a UDF that would allow for the storage and unpacking of all types of data would be a bitch.

#include 'dictmap.au3'

local $mDictMaster = _MapInit()
local $mDict2 = _MapInit()

_MapAddKeyValuePair($mDict2 , "SubKeyEntry1" , "ValueEntry1")    ; adding key/value pairs to Dict2
_MapAddKeyValuePair($mDict2 , "SubKeyEntry2" , "ValueEntry2")
_MapAddKeyValuePair($mDict2 , "SubKeyEntry3" , "ValueEntry3")

_MapAddKeyValuePair($mDictMaster , "MasterKey1" , $mDict2)   ; add Dict2 to the Master Dictionary

For $entry in $mDictMaster.Item("MasterKey1")
   msgbox(0, '' , $entry & " = " & $mDictMaster.Item("MasterKey1").item($entry))
Next

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

dictionary in dictionary is interesting me more.

  Here is a better example with languages:

#include 'dictmap.au3'

local $mDictMaster = _MapInit()
local $mEspanol = _MapInit()
local $mDeutsch = _MapInit()


_MapAddKeyValuePair($mEspanol , "Horse" , "Caballo")    ; adding key/value pairs to Spanish Dict
_MapAddKeyValuePair($mEspanol , "Cow" , "Baca")
_MapAddKeyValuePair($mEspanol , "Chicken" , "Pollo")

_MapAddKeyValuePair($mDeutsch , "Horse" , "Pferd")    ; adding key/value pairs to German Dict
_MapAddKeyValuePair($mDeutsch , "Cow" , "Kuh")
_MapAddKeyValuePair($mDeutsch , "Chicken" , "Huhn")

_MapAddKeyValuePair($mDictMaster , "Spanish" , $mEspanol)   ; add Spanish
_MapAddKeyValuePair($mDictMaster , "German" , $mDeutsch)   ; add German


msgbox(0, '' , $mDictMaster.Item("Spanish").item("Cow"))
msgbox(0, '' , $mDictMaster.Item("German").item("Chicken"))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

using that format, to build a lookup that takes the word and returns the language.

 

#include 'dictmap.au3'
#AutoIt3Wrapper_Run_Au3Check = 0


local $mDictMaster = _MapInit()
local $mEspanol = _MapInit()
local $mDeutsch = _MapInit()

_MapAddKeyValuePair($mEspanol , "Horse" , "Caballo")    ; adding key/value pairs to Spanish Dict
_MapAddKeyValuePair($mEspanol , "Cow" , "Baca")
_MapAddKeyValuePair($mEspanol , "Chicken" , "Pollo")

_MapAddKeyValuePair($mDeutsch , "Horse" , "Pferd")    ; adding key/value pairs to German Dict
_MapAddKeyValuePair($mDeutsch , "Cow" , "Kuh")
_MapAddKeyValuePair($mDeutsch , "Chicken" , "Huhn")

_MapAddKeyValuePair($mDictMaster , "Spanish" , $mEspanol)   ; add Spanish
_MapAddKeyValuePair($mDictMaster , "German" , $mDeutsch)   ; add German


msgbox(0, '' , _CheckLanguage("Pollo"))
msgbox(0, '' , _CheckLanguage("Kuh"))
msgbox(0, '' , _CheckLanguage("Horse"))
msgbox(0, '' , _CheckLanguage("Xhiken"))

Func _CheckLanguage($sString)

For $key in $mDictMaster
  For $entry in $mDictMaster($key)

    If stringinstr($sString , $entry) Then return "English"
    If stringinstr($sString , $mDictMaster($key)($entry)) Then return $key

  Next
Next

return "'" & $sString & "'" & " Was Not Found"

EndFunc

 

Edited by boththose
better

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...