iamtheky Posted August 14, 2015 Share Posted August 14, 2015 was pointed towards scripting.dictionary as I explored maps, but I got sidetracked in hashtables. Any pros / cons yall have experienced? My first hour of playing with trying to feign the behavior yielded this, which may or may not be a good starting point: *I am using integer keys because i dont know how to iterate through the collection returned from .keys, not for any legitimate reasons. expandcollapse popup$MyMap = _MapInit() _AddKeyValuePair($MyMap , 1, "hello") _AddKeyValuePair($MyMap , 2, "world") _AddKeyValuePair($MyMap , 3, "My") _AddKeyValuePair($MyMap , 4, "Name") _AddKeyValuePair($MyMap , 5, "Is") _AddKeyValuePair($MyMap , 6, "Map") _AddKeyValuePair($MyMap , 1, "world") ;fail with duplicate key msgbox(0, "Value of Key 3" , _GetValue($MyMap , 3)) msgbox(0, "Value of Key 6" , _GetValue($MyMap , 6)) msgbox(0, 'Whole Map' , _MapToString($MyMap)) Func _MapInit() Local $oHashTable = ObjCreate("System.Collections.Hashtable") If Not IsObj($oHashTable) Then Exit MsgBox(0, "Error", "Object not created") EndIf return $oHashTable EndFunc ;_MapInit Func _AddKeyValuePair($map , $key , $value) If $map.ContainsKey($key) Then msgbox(0, 'Error' , '"' & $key & '"' & ' already exists with a value of ' & '"' & $map.Item($key) & '"') Else $map.Add($key, $value) EndIf EndFunc Func _GetValue($map , $key) return $map.Item($key) EndFunc Func _MapToString($map) local $sHashTable = "" For $i = 1 to $map.count $sHashTable &= $i & " = " & $map.Item($i) & @LF Next return $sHashTable EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
guinness Posted August 15, 2015 Share Posted August 15, 2015 Nope couldn't work it out either. HashTables are quite slow in C# compared to the other data structures.expandcollapse popup#include <MsgBoxConstants.au3> ; Error constants Global Enum Step * 2 $MAP_INVALID_LIBRARY, $MAP_INVALID_HANDLE, $MAP_KEY_EXISTS Local $hMap = _Map_Init() If @error Then MsgBox($MB_SYSTEMMODAL, '', 'It appears System.Collections.Hashtable doesn''t exist on your system.') Exit EndIf Local $aStrings = ['Hello', 'World', 'My', 'Name', 'Is', 'Map'] ; Starts from zero For $i = 0 To UBound($aStrings) - 1 _Map_Add($hMap, $i, $aStrings[$i]) Next If Not _Map_Add($hMap, 2, 'World') Then ; Duplicate value exists MsgBox($MB_SYSTEMMODAL, 'Error', '"2" already exists with a value of ' & '"' & _Map_GetValue($hMap, 2) & '"') EndIf MsgBox($MB_SYSTEMMODAL, 'Value of Key 3', _Map_GetValue($hMap, 3)) MsgBox($MB_SYSTEMMODAL, 'Value of Key 6', _Map_GetValue($hMap, 5)) MsgBox($MB_SYSTEMMODAL, 'Map.ToString()', _Map_ToString($hMap)) Func _Map_Init() Local $hMap = ObjCreate('System.Collections.Hashtable') If Not IsObj($hMap) Then Return SetError($MAP_INVALID_LIBRARY, 0, Null) EndIf Return $hMap EndFunc ;==>_Map_Init Func _Map_Add(ByRef $hMap, $vKey, $vValue) ; Check if a valid 'Map' object If Not __Map_IsMap($hMap) Then Return SetError($MAP_INVALID_HANDLE, 0, False) EndIf If $hMap.ContainsKey($vKey) Then Return SetError($MAP_KEY_EXISTS, 0, False) EndIf $hMap.Add($vKey, $vValue) Return True EndFunc ;==>_Map_Add Func _Map_GetValue(ByRef $hMap, $vKey) ; Check if a valid 'Map' object If Not __Map_IsMap($hMap) Then Return SetError($MAP_INVALID_HANDLE, 0, '') EndIf Return $hMap.Item($vKey) EndFunc ;==>_Map_GetValue Func _Map_ToString($hMap) ; Check if a valid 'Map' object If Not __Map_IsMap($hMap) Then Return SetError($MAP_INVALID_HANDLE, 0, '') EndIf ; WARNING: DOESN'T WORK Local $sHashTable = '' For $vKey In $hMap.Keys() $sHashTable &= $vKey & ' = ' & $hMap.Item($vKey) & @CRLF Next Return $sHashTable EndFunc ;==>_Map_ToString Func __Map_IsMap(ByRef $hMap) Return $hMap <> Null EndFunc ;==>__Map_IsMap UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
iamtheky Posted August 15, 2015 Author Share Posted August 15, 2015 (edited) is there a most efficient way to play key-value with scripting.dictionary? google would lead me to believe I have as many choices as there are delimiters, but i have a feeling there are better tricks.nvm any of that until I can state my issue in code, because as soon as i do that I will probably have the answer.. Edited August 15, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now