Jump to content

How Dirty is this Map action?


Recommended Posts

I gave this as an answer, because it worked as i was playing.  It feels really dirty, just wanted some expert dismantling:

Local $mMap[]
$mMap['cat'] = mapappend($mMap , 'jack')
$mMap['dog'] = mapappend($mMap , 'jeff')
$mMap['pig'] = mapappend($mMap , 'john')

msgbox(0, '' , $mMap[$mMap.cat])
msgbox(0, '' , $mMap[$mMap.dog])
msgbox(0, '' , $mMap[$mMap.pig])

 

same thing i guess inspired to mimic the scripting dictionary example below:

Local $mMap[]
$mMap['cat'] = mapappend($mMap , 'jack')
$mMap['dog'] = mapappend($mMap , 'jeff')
$mMap['pig'] = mapappend($mMap , 'john')

For $each In $mMap
    If stringlen($mMap[$each]) > 1 Then ConsoleWrite(mapkeys($mMap)[$each * 2] & " = " & $mMap[$each] & @CRLF)
Next

 

Edited by boththose

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

Link to comment
Share on other sites

I do need to learn more scripting dictionary, it looks great everytime i see it.  However, my curiosity is more about the misuse of map; using the key of one entry to pull the value of another, as best I can describe.

Edited by boththose

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

Link to comment
Share on other sites

How about this?   Is there any usefulness to having the value be essentially a stored arrayfindall return of the values related to that key?

My thought was that I get to keep an order of updates, but dont know if that is accomplished other ways as well.  

 

local $mMap[]
$mMap['TestCat'] =  MapAppend($mMap , 'Entry 1 about Cat') & "|" & MapAppend($mMap , 'Entry 2 about cat') & "|" & MapAppend($mMap , 'Entry 3 about cat')
$mMap['TestDog'] =  MapAppend($mMap , 'Entry 1 about Dog') & "|" & MapAppend($mMap , 'Entry 2 about Dog') & "|" & MapAppend($mMap , 'Entry 3 about Dog')

_MapAddToKey($mMap , "TestDog" , "An additional entry in the map tied to TestDog")
_MapAddToKey($mMap , "TestCat" , "An additional entry in the map tied to TestCat")
_MapAddToKey($mMap , "TestDog" , "One last entry tied to TestDog")

msgbox(0, '' , _MasterKeyGetValues($mMap.TestDog))
msgbox(0, '' , _MasterKeyGetValues($mMap.TestCat))

Func _MapAddToKey(ByRef $sMap , $sKey , $sValue)
        $sMap[$sKey] &= "|" &  MapAppend($sMap , $sValue)
EndFunc


Func _MasterKeyGetValues($MasterKey)

local $out = ""

$aKeys = stringsplit($MasterKey , "|" , 2)
    For $i = 0 to ubound($aKeys) - 1
        $out &= $mMap[number($aKeys[$i])] & @LF
    Next

return $out
EndFunc

 

Edited by boththose
I have somehow dorked the formatting, sorry

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

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...