As usual, you access the values in tables by indexing them with
a value (for a single index) or list of values (multiple indices)
enclosed in []
's.
Deficiency: Presently, when indexing a multi-dimensional table you must provide all of the relevant indices; you can't leave one out in order to extract a sub-table.
You can also index arrays using record
's, providing the
record is comprised of values whose types match that of the table's
indices. (Any record fields whose types are themselves records
are recursively unpacked to effect this matching.) For example,
if we have:
local b: table[addr, port] of conn_id; local c = 131.243.1.10; local d = 80/tcp;
then we could index b
using b[c, d]
, but if we had:
local e = [$field1 = c, $field2 = d];
we could also index it using a[d]
You can test whether a table holds a given index using
the in
operator:
[131.243.1.10, 80/tcp] in b
or
e in b
per the examples above. In addition, if the table has only
a single index (not multi-dimensional), then you can omit
the []
's:
local active_connections: table[addr] of conn_id; ... if ( 131.243.1.10 in active_connections ) ...