Module xbt.util

Utility functions for XBTs.

Info:

  • Copyright: 2015, Matthias Hölzl
  • License: MIT, see the file LICENSE.md.
  • Author: Matthias Hölzl

Functions

random (m, n) Generate a random bounded integer.
uuid () An implementation of version 4 UUIDs.
size (t) Compute the size of a table.
equal (t1, t2, cache) Value equality for tables.
keys (t) Return a list containing the keys of a table.
addall (t1, t2) Conjoin the members of one table to another.
append (t1, t2) Append two arrays.
maybe_add (table, attribute, value) Add an attribute to a table if it doesn't already exist.
debug_print (...) Print arguments when debugging is enabled.

Fields

rng The central random number generator.
debug A flag indicating whether debug output should be shown.


Functions

random (m, n)
Generate a random bounded integer. The generated integer is between m and n (inclusive) if two arguments are provided, otherwise it is between 1 and n.

Parameters:

  • m The lower bound of the generated numbers (inclusive) if a second argument is provided, otherwise the upper bound.
  • n The upper bound of the generated number if an argument is provided.
uuid ()
An implementation of version 4 UUIDs. Generates a V4 (random) unique identifier represented as a string.

Returns:

    A string in UUID V4 format.
size (t)
Compute the size of a table. This includes all attributes and array members.

Parameters:

  • t A table

Returns:

    The number of attributes of t.
equal (t1, t2, cache)
Value equality for tables. Check whether two tables are equal as values. Recursively descends into attributes. All other values are compared using ==. Ignoeres metatables.

Parameters:

  • t1 A table.
  • t2 A table.
  • cache A cache for values that have already been compared

Returns:

    true if t1 and t2 have the same value, false otherwise.
keys (t)
Return a list containing the keys of a table.

Parameters:

  • t A table.

Returns:

    The keys of t sorted alphabetically.
addall (t1, t2)
Conjoin the members of one table to another.

Parameters:

  • t1 The table to which the new values are added. Modified destructively.
  • t2 The table containing the new keys

Returns:

    t1, modified with the key/value bindings of t2 Keys occurring in both tables get the value of t2.
append (t1, t2)
Append two arrays.

Parameters:

  • t1 An array. Destructively modified.
  • t2 An array.

Returns:

    t1, extended with the values of t2
maybe_add (table, attribute, value)
Add an attribute to a table if it doesn't already exist.

Parameters:

  • table The table to which the attribute is added
  • attribute The name of the attribute as string
  • value The value of the attribute. Defaults to {}

Returns:

    table, with the attribute/value pair added if no value for attribute was present, the unmodified table otherwise.
debug_print (...)
Print arguments when debugging is enabled.

Parameters:

  • ... Any number of arguments will be passed on to print.

Fields

rng
The central random number generator. To ensure that experiments can be repeated we use a single random number generator in all places where random numbers are needed, and we add its seed to the description of the experiment.
debug
A flag indicating whether debug output should be shown.
generated by LDoc 1.4.3 Last updated 2015-03-03 12:33:49