· 8 years ago · Mar 14, 2018, 06:20 AM
1Hash Tables
2
3
4
5Hash tables allow you to efficiently store large amounts of information which can be quickly referenced and retrieved later on.
6
7
8
9A hash table can be created, freed, referenced, or modified using the following commands and identifiers.
10
11
12
13/hmake -s <name> <N>
14
15Creates a new hash table with N slots.
16
17
18
19A hash table can store an unlimited number of items regardless of the N you choose, however the bigger N is, the faster it will work, depending on the number of items stored.
20
21
22
23eg. if you expect that you'll be storing 1000 items in the table, a table of N set to 100 is quite sufficient.
24
25
26
27The -s switch makes the command display the result.
28
29
30
31/hfree -sw <name>
32
33Frees an existing hash table.
34
35
36
37The -w switch indicates that name is a wildcard, all matching tables are freed.
38
39
40
41/hadd -smbczuN <name> <item> [data | &binvar]
42
43Adds an item to an existing hash table.
44
45
46
47If the item you're adding already exists, the old item is replaced.
48
49
50
51The -m switch makes /hadd create the hash table if it doesn't already exist.
52
53
54
55The -uN switch unsets the item after N seconds.
56
57
58
59The -b indicates that you're adding a &binvar item to the hash table.
60
61
62
63The -c switch chops the &binvar up to the first null value and treats it as plain text.
64
65
66
67The -z switch decreases hash item once per second until it reaches zero and then unsets it.
68
69
70
71The /hinc and /hdec commands use the same parameters as /hadd and increase or decrease the number value of an item.
72
73
74
75When used with /hinc or /hdec, the -c switch increases or decreases the value once per second.
76
77
78
79/hdel -sw <name> <item>
80
81Deletes an item from a hash table.
82
83
84
85The -w switch indicates that item is a wildcard, all matching items are freed.
86
87
88
89/hload -sbni <name> <filename> [section]
90
91/hsave -sbniau <name> <filename> [section]
92
93Load or save a table to/from a file.
94
95
96
97These load/save plain text to a text file, with item and data on separate lines. $cr and $lf characters are stripped from text when saving as plain text.
98
99
100
101The -b switch loads or saves binary files. $cr and $lf are preserved when saving as binary files.
102
103
104
105You can use -n to load or save files as data only, with no items. When loading with -n each line of data is assigned an N item value, starting at N = 1.
106
107
108
109/hsave also supports -a to append to an existing file instead of overwriting it.
110
111
112
113By default /hsave excludes items that are in the /hadd -uN unset list, the -u switch forces it to include the unset items.
114
115
116
117The -i switch treats the file as an ini file. You can specify an optional section name after the filename.
118
119
120
121Note: /hload does not create the table, it must already have been created by /hmake.
122
123
124
125$hget(name/N)
126
127Returns name of a hash table if it exists, or returns the name of the Nth hash table.
128
129
130
131Properties: size
132
133
134
135$hget(moo).size returns the N size of table, as specified in /hmake
136
137
138
139$hget(name/N, item)
140
141Returns the data associated with an item in the specified hash table.
142
143
144
145Properties: unset
146
147
148
149The unset property returns the time remaining before an item is unset.
150
151
152
153$hget(name/N, item, &binvar)
154
155Assigns the contents of an item to a &binvar.
156
157
158
159$hget(name/N, N).item
160
161This allows you to reference the table as an index from 0 to N, in order to look up the Nth item in the table.
162
163
164
165If N is zero, returns the total number of items in the table.
166
167
168
169You can also reference the Nth data value directly with $hget().data.
170
171
172
173Note: This method is provided as a convenience, it is not an efficient way to use the hash table.
174
175
176
177$hfind(name/N, text, N, M)
178
179Searches table for the Nth item name which matches text. Returns item name.
180
181
182
183Properties: data
184
185
186
187If you specify the .data property, searches for a matching data value.
188
189
190
191M is optional, and can be:
192
193
194
195 n normal text comparison (default if M isn't specified)
196
197 w text is wildcard text
198
199 W hash table item/data is wildcard text
200
201 r text is regular expression
202
203 R hash table item/data is regular expression