Class pl.OrderedMap

OrderedMap, a map which preserves ordering.

Derived from pl.Map.

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

Methods

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

Metamethods

pl.OrderedMap:__pairs () iterate over an ordered map (5.2).
pl.OrderedMap:__tostring () string representation of an ordered map.


Methods

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

Parameters:

pl.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 tab a table.

Returns:

  1. the map, or nil in case of error
  2. the error message
pl.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
pl.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 int a position starting at 1
  • key the key
  • val the value; if nil use the old value
pl.OrderedMap:keys ()
return the keys in order. (Not a copy!)

Returns:

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

Returns:

    List
pl.OrderedMap:sort (cmp)
sort the keys.

Parameters:

  • cmp func a comparison function as for table.sort

Returns:

    the map
pl.OrderedMap:iter ()
iterate over key-value pairs in order.

Metamethods

pl.OrderedMap:__pairs ()
iterate over an ordered map (5.2).
pl.OrderedMap:__tostring ()
string representation of an ordered map.
generated by LDoc 1.4.6 Last updated 2017-07-18 16:28:41