Jump to content

UDF - Tables Library - RFC


blindwig
 Share

Recommended Posts

I'm wroking on writing a small UDF library for a variable type that I call "Tables". These are called other things by other people - dictionaries, maps, hashes, etc

A table is a 2-dimensional array, where the 2nd dimension is normally 2.

the value at [0][0] is a number telling the number of rows in the table.

The values at [x][0] are the keys (unique) and the values at [x][1] are the values associated with these keys.

An example of this is what is returned by the IniReadSection function.

I'm writing a UDF library to create a table, add key/value entrie(s), and to retrieve a value based on a key.

Has anyone else done something like this, or is there a set of functions to do this already out there somewhere? Any comments?

Link to comment
Share on other sites

Well, I'll post my functions here, if anyone wants them:

And here's the headers, since there isn't much documentation in the file itself (it's still a work in progress) I think they're pretty self-explainatory, but here goes:

$_TableDefaultLength=20

;A table is created at default length if a length is not given

$_TableDefaultIncrease=20

;If a table has no room for another key, then it will be increased by this size.

Func _TableCreate(ByRef $Table, $Length = -1, $Width = 2)

;This will create a new table in $Table

Func _TableIsValid($Table)

;This will verify that $Table is a valid table, and will return true/false

Func _TableSetValue(ByRef $Table, $Key, $Value)

;This will set $Key in $Table to $Value. If $Key doesn't exist, it is added

Func _TableGetIndex($Table, $Key)

;This will return the index in $Table where $Key resides. Do not save this value, as it could change if the table is compressed, sorted, or otherwise optimized.

Func _TableGetValue($Table, $Key, $Column=1, $Default='')

;Returns the value of $Key in $Table. Returns $Default if non-existant. $Key is case-insensative

Func _TablePrint($Table, $Delim=',', $EOL=@CRLF)

;This is a method for displaying $Table in ASCII mode. $Delim will be between columns, and $EOL will be added to the end of each line except the last one.

Func _TableGetKeys($Table)

;This will return an array of the keys in $Table. [0]=x and [1]..[x] are the keys.

MWR_Tables.au3

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