Jump to content
Sign in to follow this  
Nutster

Associative Array functions

Recommended Posts

So my goal here is to sort the whole list ascending on the 1st column of data.

I was thinking i could pull the array into an array on my main program. then sort that as i write it out to a file.

Share this post


Link to post
Share on other sites

JasonSiegrist,

To get the key-value pairs into a sorted array you will need another step. Create a suitable array to hold the pairs and then fill it as you can see here:

#include <Array.au3>
#include <AssocArrays.au3>

; Create assoc array
Global $aArray
AssocArrayCreate($aArray, 7)

; Fill assoc array
AssocArrayAssign($aArray, "Fred", 1)
AssocArrayAssign($aArray, "Tom", 2)
AssocArrayAssign($aArray, "Dick", 3)
AssocArrayAssign($aArray, "Harry", 4)

; Generate list of keys
$aList = AssocArrayKeys($aArray)

; And sort it
_ArraySort($aList)

; Create an array to hold keys and values
Global $aPairs[UBound($aList)][2]

; And populate it
For $i = 0 To UBound($aList) - 1
    ; Insert the sorted key
    $aPairs[$i][0] = $aList[$i]
    ; Insert the associated value
    $aPairs[$i][1] = AssocArrayGet($aArray, $aList[$i])
Next

; Display sorted list
_ArrayDisplay($aPairs, "Sorted Pairs")

All clear? :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

YES thank you ... then I can WRITE it out ... thank you...

that is what i was thinking but I was not totally sure how to do it ...

Share this post


Link to post
Share on other sites

M23 thank you for the help... I thought I understood it ... but i guess I am just not as smart as i thought I was...

Here is what I am trying to do with my Function. No matter what I do i am getting an error. or the output is incomplete.

The error i get is...

Line 554 (File

“D:Usersiasonfish.au3”):

FileWriteLine($fOut, $aPairs[Oj[sij & ‘, “& $aPairs[1][si])

FileWriteLine($fOut. ^ ERROR

Error Array variable has incorrect number of subscripts or subscript

dimension range exceeded.

Global $sFilename = "D:UsersJasonLiveWell.txt"


Func AASS() ; AssocArraySave&Sort

;-- this did not work...

;$fOut = FileOpen($sFilename, 2); maybe change this to a 1 and add a TIME Stamp before the FILE CLOSE

; And populate it
;For $i = 1 To UBound($aList) - 1
; Insert the sorted key
;$aPairs[$i][0] = $aList[$i]
; Insert the associated value
;$aPairs[$i][1] = AssocArrayGet($hipBag, $aList[$i])
;FileWriteLine($fOut, StringQuote($aPairs[0][$i]) & ", " & StringQuote($aPairs[1][$i]))
;_FileWriteLog ($sFilename2, StringQuote($aPairs[0][$i]) & ", " & StringQuote($aPairs[1][$i]))
;Next
;FileClose($fOut)





Global $aArray, $aList
Local $fOut, $I

; Generate list of keys
$aList = AssocArrayKeys($hipBag)

; And sort it
_ArraySort($aList)

; Create an array to hold keys and values
Global $aPairs[UBound($aList)][2]

; And populate it
For $i = 1 To UBound($aList) - 1
; Insert the sorted key
$aPairs[$i][0] = $aList[$i]
; Insert the associated value
$aPairs[$i][1] = AssocArrayGet($hipBag, $aList[$i])
Next

$i = 0

$fOut = FileOpen($sFilename, 2); maybe change this to a 1 and add a TIME Stamp before the FILE CLOSE
; And populate it
For $i = 1 To UBound($aPairs) - 1
FileWriteLine($fOut, ($aPairs[0][$i]) & ", " & ($aPairs[1][$i]))
;_FileWriteLog ($sFilename2, StringQuote($aPairs[0][$i]) & ", " & StringQuote($aPairs[1][$i]))
Next
FileClose($fOut)

EndFunc ;==>AASS
Edited by JasonSiegrist

Share this post


Link to post
Share on other sites

JasonSiegrist,

Why reinvent the wheel - there is an existing function to write a file from an array: ;)

#include <Array.au3>
#include <AssocArrays.au3>
#include <File.au3>

Global $sFilename = @ScriptDir & "LiveWell.txt"

; Create assoc array
Global $aArray
AssocArrayCreate($aArray, 7)

; Fill assoc array
AssocArrayAssign($aArray, "Fred", 1)
AssocArrayAssign($aArray, "Tom", 2)
AssocArrayAssign($aArray, "Dick", 3)
AssocArrayAssign($aArray, "Harry", 4)

AASS()

Func AASS() ; AssocArraySave&Sort

    ; Generate list of keys
    $aList = AssocArrayKeys($aArray)

    ; And sort it
    _ArraySort($aList)

    ; Create an array to hold keys and values
    Global $aPairs[UBound($aList)][2]

    ; And populate it
    For $i = 0 To UBound($aList) - 1
        ; Insert the sorted key
        $aPairs[$i][0] = $aList[$i]
        ; Insert the associated value
        $aPairs[$i][1] = AssocArrayGet($aArray, $aList[$i])
    Next

    ; Write the array to a file
    _FileWriteFromArray($sFilename, $aPairs, 0, 0, " = ") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc

That writes the file perfectly for me. How about you? :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

That was too simple... I am sorry I did not find that with out bugging you... thank you again!!!!

New Error... :-(

Line272 (File “D:Program Files (x86)AutoIt3IncludeFile.au3"):

$s_Temp &= $s_Delim & $a_Array[$x][$y]

$s_Temp &= $s_Delim & ERROR

Error Array variable has incorrect number of subscripts or subscript

dimension range exceeded.

Edited by JasonSiegrist

Share this post


Link to post
Share on other sites

JasonSiegrist,

I need to see all of the script to deal with that. You are asking an array to go outside the size you have initially set and we need to find out where you do both. :)

M23

P.S. Once you reply I will move "our" section of the thread into a separate topic in the "General Help" section as we are beginning to get a long way away from the UDF to which this one should be dedicated. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

JasonSiegrist,

Why reinvent the wheel - there is an existing function to write a file from an array: ;)

#include <Array.au3>
#include <AssocArrays.au3>
#include <File.au3>

Global $sFilename = @ScriptDir & "LiveWell.txt"

; Create assoc array
Global $aArray
AssocArrayCreate($aArray, 7)

; Fill assoc array
AssocArrayAssign($aArray, "Fred", 1)
AssocArrayAssign($aArray, "Tom", 2)
AssocArrayAssign($aArray, "Dick", 3)
AssocArrayAssign($aArray, "Harry", 4)

AASS()

Func AASS() ; AssocArraySave&Sort

; Generate list of keys
$aList = AssocArrayKeys($aArray)

; And sort it
_ArraySort($aList)

; Create an array to hold keys and values
Global $aPairs[UBound($aList)][2]

; And populate it
For $i = 0 To UBound($aList) - 1
; Insert the sorted key
$aPairs[$i][0] = $aList[$i]
; Insert the associated value
$aPairs[$i][1] = AssocArrayGet($aArray, $aList[$i])
Next

; Write the array to a file
_FileWriteFromArray($sFilename, $aPairs, 0, 0, " = ") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc

That writes the file perfectly for me. How about you? :)

M23

M23,

just wanted to clsoe the loop here on this one... The code you have there did not work for me with the current version. I had to go to the BETA version for the error to go away.

Share this post


Link to post
Share on other sites

JasonSiegrist,

You are quite correct - sorry not to have noticed myself. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I have found a strange and very repetable problem with AssociativeArrays.au3. It is telling me a value ("4_1") does not exist when it does exist. I can delete all the entries in the AA (the one which AA says doesn't exist won't delete, it errors), and then get all the keys from the AA, and the keys show this one entry still exists.

#include <AssocArrays.au3>

AutoItSetOption("MustDeclareVars", 1)

Local $hash_last_id_clicked[1], $keys, $keys_leftover

AssocArrayCreate($hash_last_id_clicked, 200, 10)


; Add some keys.
AssocArrayAssign($hash_last_id_clicked, '1_1', '')
AssocArrayAssign($hash_last_id_clicked, '10_1', '')
AssocArrayAssign($hash_last_id_clicked, '10_2', '')
AssocArrayAssign($hash_last_id_clicked, '10_3', '')
AssocArrayAssign($hash_last_id_clicked, '10_4', '')
AssocArrayAssign($hash_last_id_clicked, '8_1', '')
AssocArrayAssign($hash_last_id_clicked, '15_1', '')
AssocArrayAssign($hash_last_id_clicked, '14_1', '')
AssocArrayAssign($hash_last_id_clicked, '9_1', '')
AssocArrayAssign($hash_last_id_clicked, '13_1', '')
AssocArrayAssign($hash_last_id_clicked, '12_1', '')
AssocArrayAssign($hash_last_id_clicked, '4_1', '') ; <<<<< This is the problem key
AssocArrayAssign($hash_last_id_clicked, '5_1', '')
AssocArrayAssign($hash_last_id_clicked, '7_1', '')
AssocArrayAssign($hash_last_id_clicked, '6_1', '')
AssocArrayAssign($hash_last_id_clicked, '11_1', '')
AssocArrayAssign($hash_last_id_clicked, '2_1', '')


; Extract all the keys, and delete them from the hash
$keys = AssocArrayKeys($hash_last_id_clicked)

For $last_id_clicked In $keys
    If AssocArrayExists($hash_last_id_clicked, $last_id_clicked) Then
        If AssocArrayDelete($hash_last_id_clicked, $last_id_clicked) Then
            ConsoleWrite('Removed ' & $last_id_clicked & @LF)
        Else
            ConsoleWrite('FAILED: Removed ' & $last_id_clicked & @LF)
       EndIf
    Else
       ConsoleWrite('Does not exist: |' & $last_id_clicked & '|' & @LF)
    EndIf
Next

; This shows 4_1 is still in hash.
$keys_leftover = AssocArrayKeys($hash_last_id_clicked)

For $last_id_clicked In $keys_leftover

ConsoleWrite('Key left in hash: |' & $last_id_clicked & '|' & @LF)

Next

The console log shows:

Removed 14_1
Removed 2_1
Removed 10_3
Removed 11_1
Removed 10_1
Removed 13_1
Removed 8_1
Removed 12_1
Does not exist: |4_1|    <<<<<< PROBLEM
Removed 1_1
Removed 6_1
Removed 9_1
Removed 10_4
Removed 7_1
Removed 10_2
Removed 5_1
Removed 15_1

Key left in hash: |4_1|  <<<<<< PROBLEM
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||
Key left in hash: ||

I log vertical bars just so it's clear there are no leading or trailing characters.

I'm using AA 3.3.0.0, AutoIT 3.3.8.1

I hope Dave is still supporting this addon. It's very useful.

EDIT: Just for fun, I removed the underscores from the keys. The problem goes away. The problem is in some way related to the underscores in the key value. For me, I can transform my keys into values without underscores. Therefore it's not an immediate problem. But, still, it would be good to get this fixed.

Thanks!

Edited by az2000

Share this post


Link to post
Share on other sites

az2000,

I can reproduce the problem - and solve it by removing the keys from the bottom up just as you would with a normal array. Look for the <<<<<<<< line: :)

#include <AssocArrays.au3>

AutoItSetOption("MustDeclareVars", 1)

Local $hash_last_id_clicked[1], $keys, $keys_leftover

AssocArrayCreate($hash_last_id_clicked, 200, 10)

; Add some keys.
AssocArrayAssign($hash_last_id_clicked, '1_1', '')
AssocArrayAssign($hash_last_id_clicked, '10_1', '')
AssocArrayAssign($hash_last_id_clicked, '10_2', '')
AssocArrayAssign($hash_last_id_clicked, '10_3', '')
AssocArrayAssign($hash_last_id_clicked, '10_4', '')
AssocArrayAssign($hash_last_id_clicked, '8_1', '')
AssocArrayAssign($hash_last_id_clicked, '15_1', '')
AssocArrayAssign($hash_last_id_clicked, '14_1', '')
AssocArrayAssign($hash_last_id_clicked, '9_1', '')
AssocArrayAssign($hash_last_id_clicked, '13_1', '')
AssocArrayAssign($hash_last_id_clicked, '12_1', '')
AssocArrayAssign($hash_last_id_clicked, '4_1', '')
AssocArrayAssign($hash_last_id_clicked, '5_1', '')
AssocArrayAssign($hash_last_id_clicked, '7_1', '')
AssocArrayAssign($hash_last_id_clicked, '6_1', '')
AssocArrayAssign($hash_last_id_clicked, '11_1', '')
AssocArrayAssign($hash_last_id_clicked, '2_1', '')

; Extract all the keys, and delete them from the hash
$keys = AssocArrayKeys($hash_last_id_clicked)

For $i = UBound($keys) - 1 To 0 Step -1  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If AssocArrayExists($hash_last_id_clicked, $keys[$i]) Then
        If AssocArrayDelete($hash_last_id_clicked, $keys[$i]) Then
            ConsoleWrite('Removed ' & $keys[$i] & @LF)
        Else
            ConsoleWrite('FAILED: Removed ' & $keys[$i] & @LF)
       EndIf
    Else
       ConsoleWrite('Does not exist: |' & $keys[$i] & '|' & @LF)
    EndIf
Next

; This shows 4_1 is still in hash.
$keys_leftover = AssocArrayKeys($hash_last_id_clicked)

For $last_id_clicked In $keys_leftover

ConsoleWrite('Key left in hash: |' & $last_id_clicked & '|' & @LF)

Next

I imagine that it is the same problem as with normal arrays - if you delete from the top down you get indexing problems as you progress. And I would always recommend using For...To...Next loops on arrays - keep the For...In...Next for object collections. ;)

M23

P.S. Just seen your edit - as you can see from the above you can keep your underscores. :D


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba, thanks for your prompt response. But, why would removing the underscore fix the problem if the problem is deleting the entries in the wrong order?

I changed the "_" to "-" and a different value got "lost" in the hash. I changed it to "." and it works. Strange behavior(?).

I add and remove keys in much larger process of encountering data in a web page. I could save the "keys to delete" in a normal array. At the end of the process I could loop through that array from bottom to top, using those values to delete from the hash (instead of doing it as those values are encountered). So, your suggestion is useful.

Thanks!

Share this post


Link to post
Share on other sites

az2000,

I tried removing the underscores and it still errored - it was only by reversing the delete order that I got a repeatable valid deletion process. I think the underscore factor is a red herring. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I think the underscore factor is a red herring. ;)

You're right. I ran my larger process (which creates 900 hash entries) using "." as the delimiter between the numbers. Other entries became "lost" in the hash. I'll try maintaining an order.

It's been 3-4 years since I've visited this topic. (AA always met my needs.). Have any better solutions developed for associative arrays?

Thanks!

Share this post


Link to post
Share on other sites

az2000,

None that I have found as reliable as this one. I still hope we might get a native implementation one day. o:)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

It sounds like I have a bug in the delete code.  This could happen if a hash collision is being handled incorrectly during deletion.

For example:

Local $HashSet(1)

AssocArrayCreate($HashSet, 6) ; The overhead is not worth it for such a small list.
; This is for illistrative purposes only.  They may or may not map this way.
AssocArrayAssign($HashSet, "M", 1) ; Hash index 2
AssocArrayAssign($HashSet, "D", 2) ; Hash index 3
AssocArrayAssign($HashSet, "Y", 3) ; Hash index 2.  This collides and gets moved down to 4, the next available location.
AssocArrayAssign($HashSet, "T", 4) ; Hash index 1.
; At this point the array looks like:
; Index   Key     Value
; 0
; 1       T       4
; 2       M       1
; 3       D       2
; 4       Y       3
; Now to delete an entry.
AssocArrayDelete($HashSet, "M")
; Now the array looks like:
; Index   Key     Value
; 0
; 1       T       4  - Hash Index 1.  Good.
; 2
; 3       D       2  - Hash Index 3.  Good.
; 4       Y       3  - Hash Index 2.  Good luck finding it here!

Before the deletion, the hash search function could look for "Y" and start looking at the calculated hash index of 2.  That has "M", which is not what it is looking for, so it checks the next elements until it finds either 1) the element it is looking for or 2) an empty element, in which case it says it is not found.

When the hash search function looks for "Y" after "M" has been deleted, it will look at 2; finding that empty, it will say "Y" is not in the hash table, even though it is still there, just in the wrong place.  "Y" should have been moved up during the deletion process.

When the elements are removed in the reversed order that they were added, you remove the "Y" first, before "M", so the hash collision is removed before this becomes an issue.

Well that is my analysis anyway; I could be wrong and something else altogether is happening.

If we are patient, the original author could come back and fix the bug in the delete code.  Oh, wait, that's me. ;) I guess I should look at this.  Thanks for the testing set that I can use to verify when I fix this.

Edited by Nutster
Improve explanation.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Nutster,

Nice to see you around again after so long. Given that Maps are still only a feature in the Beta trunk, I am looking forward to the new version of this UDF.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Well, I have found and fixed the problem in the AssocArrayDelete function, but have uncovered some other bugs.  Also, I am adding AssocArrayDisplay(), which returns a string with all the assigned key-value pairs in the sequence in the array and AssocArraySorted(), which returns a string with all the assigned key-value pairs, in order by the key.  I am adding a couple of support routines to help with AssocArraySorted, like other support routines, they are not meant to be called directly.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...