Module pl.OrderedMap

OrderedMap, a map which preserves ordering.

Derived from pl.Map .

Dependencies: pl.utils , pl.tablex , pl.List

Functions

OrderedMap:_init (t) construct an OrderedMap.
OrderedMap:update (t) update an OrderedMap using a table.
OrderedMap:set (key, val) set the key’s value.
OrderedMap:insert (pos, key, val) insert a key/value pair before a given position.
OrderedMap:keys () return the keys in order.
OrderedMap:values () return the values in order.
OrderedMap:sort (cmp) sort the keys.
OrderedMap:iter () iterate over key-value pairs in order.


Functions

OrderedMap:_init (t)
construct an OrderedMap. Will throw an error if the argument is bad.

Parameters:

OrderedMap:update (t)
update an OrderedMap using a table.
If the table is itself an OrderedMap, then its entries will be appended.
if it s a table of the form {{key1=val1},{key2=val2},…} these will be appended.
Otherwise, it is assumed to be a map-like table, and order of extra entries is arbitrary.

Parameters:

  • t: a table.

Returns:

  1. the map, or nil in case of error
  2. the error message
OrderedMap:set (key, val)
set the key’s value. This key will be appended at the end of the map.
If the value is nil, then the key is removed.

Parameters:

  • key: the key
  • val: the value

Returns:

    the map
OrderedMap:insert (pos, key, val)
insert a key/value pair before a given position. Note: if the map already contains the key, then this effectively moves the item to the new position by first removing at the old position. Has no effect if the key does not exist and val is nil

Parameters:

  • pos: a position starting at 1
  • key: the key
  • val: the value; if nil use the old value
OrderedMap:keys ()
return the keys in order. (Not a copy!)

Returns:

    List
OrderedMap:values ()
return the values in order. this is relatively expensive.

Returns:

    List
OrderedMap:sort (cmp)
sort the keys.

Parameters:

Returns:

    the map
OrderedMap:iter ()
iterate over key-value pairs in order.
generated by LDoc 1.2