9. Specific Datatype Modules |
Module String |
string String.implode_nicely(array(string|int|float) foo, string|void separator)
This function implodes a list of words to a readable string, e.g. ({"straw","berry","pie"}) becomes "straw, berry and pie". If the separator is omitted, the default is "and". If the words are numbers they are converted to strings first.
`*()
string String.capitalize(string str)
Convert the first character in str to upper case, and return the new string.
lower_case() , upper_case()
string String.sillycaps(string str)
Convert the first character in each word (separated by spaces) in str to upper case, and return the new string.
string String.common_prefix(array(string) strs)
Find the longest common prefix from an array of strings.
int(0..100) String.fuzzymatch(string a, string b)
This function compares two strings using a fuzzy matching routine. The higher the resulting value, the better the strings match.
Array.diff() , Array.diff_compare_table() Array.diff_longest_sequence()
string String.soundex(string word)
Returns the soundex value of word according to the original Soundex algorithm, patented by Margaret OŽDell and Robert C. Russel in 1918. The method is based on the phonetic classification of sounds by how they are made. It was only intended for hashing of english surnames, and even at that it isn't that much of a help.
string String.int2roman(int m)
Converts the provided integer to a roman integer (i.e. a string).
Throws an error if m is outside the range 0 to 10000.
string String.int2size(int size)
Returns the size as a memory size string with suffix, e.g. 43210 is converted into "42.2 kb". To be correct to the latest standards it should really read "42.2 KiB", but we have chosen to keep the old notation for a while. The function knows about the quantifiers kilo, mega, giga, tera, peta, exa, zetta and yotta.
Throws an error is size is less than zero.
string String.expand_tabs(string s, int|void tab_width, string|void substitute_tab, string|void substitute_space, string|void substitute_newline)
Expands tabs in a string to ordinary spaces, according to common tabulation rules.
string String.int2char(int x)
Same as sprintf("%c",x);
sprintf()
string String.int2hex(int x)
Same as sprintf("%x",x);
sprintf()
int String.count(string haystack, string needle)
Count the number of non-overlapping times the string needle occurrs in the string haystack .
search() , `/()
string String.trim_whites(string s)
Trim leading and trailing spaces and tabs from the string s .
string String.trim_all_whites(string s)
Trim leading and trailing white spaces characters (space, tab, newline and carriage return) from the string s .
int(8..8)|int(16..16)|int(32..32) String.width(string s)
Returns the width of a string.
Three return values are possible:
|
CLASS String.Buffer |
A buffer, used for building strings. It's conceptually similar to a string, but you can only add strings to it, and you can only get the value from it once.
There is a reason for those seemingly rather odd limitations, it makes it possible to do some optimizations that really speed things up.
You do not need to use this class unless you add very many strings together, or very large strings.
For the fastest possible operation, write your code like this:
String.Buffer b = String.Buffer( ); function add = b->add; .. call add several times in code ... string result = b->get(); // also clears the buffer
void String.Buffer(int initial_size)
Initializes a new buffer.
If no initial_size is specified, 256 is used. If you know approximately how big the buffer will be, you can optimize the operation of add() (slightly) by passing the size to this function.
int add(string ... data)
Adds data to the buffer. Returns the size of the buffer.
string get_copy()
Get the data from the buffer. Significantly slower than get , but does not clear the buffer.
string get()
Get the data from the buffer.
This will clear the data in the buffer
int _sizeof()
Returns the size of the buffer.
CLASS String.SplitIterator |
void String.SplitIterator(string buffer, int|array(int)|multiset(int) split_set, int|void flags, function(:string)|void feed)
Module String.Elite |
string String.Elite.elite_word(string in, void|int(0..100) leetp, void|int(0..2) eightbit)
Translates one word to 1337. The optional argument leetp is the maximum percentage of leetness (100=max leet, 0=no leet). elite_word only do character-based translation, for instance from "k" to "|<", but no language translation (no "cool" to "kewl").
string String.Elite.elite_string(string in, void|int(0..100) leetp, void|int(0..1) eightbit)
Translates a string to 1337. The optional argument leetp is the maximum percentage of leetness (100=max leet, 0=no leet).
The translation is performed in three steps, first the neccesary elite translations (picture -> pic, cool->kewl etc), then optional translations (ok->k, dude->dood, -ers -> -orz), then calls elite_word on the resulting words.
Module String.HTML |
Functions that helps generating HTML. All functions generates HTML that is XHTML compliant as well as backwards compatible with old HTML standards in what extent is possible.
string String.HTML.select(string name, array(string)|array(array(string)) choices, void|string selected)
Creates an HTML select list.
The name of the select list. Will be used in the name attribute of the select element.
May either be an array of strings, where each string is a choice, or an array of pairs. A pair is an array with two strings. The first string is the value of the choice while the second string is the presentation text associated with the value.
The value that should be selected by default, if any.
select("language", ({ ({ "eng", "English" }), ({ "swe", "Swedish" }), ({ "nor", "Norwegian" }) }), "swe");
string String.HTML.simple_obox(array(array(string)) rows, void|string frame_color, void|string cell_color, void|string width, void|string padding, void|function(int:string) cell_callback)
This function should solve most of the obox needs that arises. It creates a table out of the array of arrays of strings fed into it. The tables will (with default settings) have a thin black outline around the table and between its cells. Much effort has gone into finding a simple HTML reresentation of such obox that is rendered in a similar way in all popular browsers. The current implementation has been tested against IE, Netscape, Mozilla, Opera and Konquest.
Simply an array of arrays with strings. The strings are the values that should appear in the table cells. All rows should have equal number of cells, otherwise the result will not be very eye pleasing.
The color of the surrounding frame. Defaults to "#000000".
The background color of the cells. Defaults to "#ffffff".
The border width. Defaults to "1".
The amount of padding in each cell. Defaults to "3".
If provided, the cell callback will be called for each cell. As in parameters it will get the current x and y coordinates in the table. The upper left cell is 0,0. In addition to the coordinates it will also recieve the background color and the contents of the current cell. It is expected to return a td-element.
function cb = lambda(int x, int y, string bgcolor, string contents) { if(y%2) return "<td bgcolor='#aaaaff'>"+contents+"</td>"; return "<td bgcolor='"+bgcolor+"'>"+contents+"</td>"; } simple_obox(my_rows, "#0000a0", 0, "1", "3", cb);
pad_rows
array(array(string)) String.HTML.pad_rows(array(array(string)) rows, void|string padding)
Pads out the rows in a array of rows to equal length. The new elements in the rows will have the value provided in padding , or " ".
CLASS String.HTML.OBox |
Provides the same functionality as the simple_obox function, in a "streaming" way. The real gain is different addtition methods as well as the possibility to change the cell callback at any time.
simple_obox
void String.HTML.OBox(void|string frame_color, void|string cell_color, void|string width, void|string padding, void|function(int:string) cell_callback)
void set_cell_callback(function(int:string) cell_callback)
void set_extra_args(mapping(string:string) extra_args)
The argument in the mapping will be added to all created table cells.
void set_extra_args(array(mapping(string:string)) extra_args)
The argument in the mappings will be added to the cell in the cooresponding column of the table.
void add_raw_cell(string cell)
Adds this cell to the table unmodified, e.g. it should have an enclosing td or th element.
void add_tagdata_cell(string tag, mapping(string:string) args, string contents)
Creates a cell from the provided arguments and adds it to the table.
The name of the element that should be produces. Typically "td" or "th".
A mapping with the elements attributes.
The element contents.
void add_cell(string contents)
Adds a cell with the provided content.
void new_row()
Begin a new row. Succeeding cells will be added to this row instead of the current.
void add_row(array(string) cells)
Adds a complete row. If the current row is nonempty a new row will be started.
void pad_rows()
Ensures that all rows have the same number of cells.
string render()
Returns the result.
mixed cast(string to)
It is possible to case this object to a string, which does the same as calling render , and to an array, which returns the cells in an array of rows.
Module Array |
array(int) Array.interleave_array(array(mapping(int:mixed)) tab)
Interleave a sparse matrix.
Returns an array with offsets that describe how to interleave the rows of tab .
array(int) Array.longest_ordered_sequence(array a)
Find the longest ordered sequence of elements.
This function returns an array of the indices in the longest ordered sequence of elements in the array.
diff()
array Array.permute(array in, int number)
Give a specified permutation of an array.
The number of permutations is equal to
(the factorial of the size of the given array).sizeof(in )!
shuffle()
array(array(array)) Array.diff(array a, array b)
Calculates which parts of the arrays that are common to both, and which parts that are not.
Returns an array with two elements, the first is an array of parts in array a , and the second is an array of parts in array b .
diff_compare_table() , diff_longest_sequence() , String.fuzzymatch()
array(array(int)) Array.diff_compare_table(array a, array b)
Returns an array which maps from index in a to corresponding indices in b .
> Array.diff_compare_table( ({ "a","b","c" }), ({ "b", "b", "c", "d", "b" }));
Result: ({
({ }),
({
0,
1,
4
}),
({
2
})
})
diff() , diff_longest_sequence() , String.fuzzymatch()
array(int) Array.diff_longest_sequence(array a, array b)
Gives the longest sequence of indices in b that have corresponding values in the same order in a .
diff() , diff_compare_table() , String.fuzzymatch()
array(int) Array.diff_dyn_longest_sequence(array a, array b)
Gives the longest sequence of indices in b that have corresponding values in the same order in a .
This function performs the same operation as diff_longest_sequence() , but uses a different algorithm, which in some rare cases might be faster (usually it's slower though).
diff_longest_sequence() , diff() , diff_compare_table() , String.fuzzymatch()
array Array.uniq(array a)
Remove elements that are duplicates.
This function returns an copy of the array a with all duplicate values removed. The order of the values is kept in the result.
array(mixed) Array.splice(array(mixed) arr1, array(mixed) arr2, array(mixed) ... more_arrays)
Splice two or more arrays.
This means that the the array becomes an array of the first element in the first given array, the first argument in next array and so on for all arrays. Then the second elements are added, etc.
`/() , `*() , `+() , `-() , everynth()
array(mixed) Array.everynth(array(mixed) a, void|int n, void|int start)
Return an array with every n :th element of the array a .
If n is zero every other element will be returned.
splice() , `/()
array(array) Array.transpose(array(array) matrix)
mixed Array.reduce(function fun, array arr, mixed|void zero)
reduce() sends the first two elements in arr to fun , then the result and the next element in arr to fun and so on. Then it returns the result. The function will return zero if arr is the empty array. If arr has only one element, that element will be returned.
rreduce()
mixed Array.rreduce(function fun, array arr, mixed|void zero)
rreduce() sends the last two elements in arr to fun , then the third last element in arr and the result to fun and so on. Then it returns the result. The function will return zero if arr is the empty array. If arr has only one element, that element will be returned.
reduce()
array Array.shuffle(array arr)
shuffle() gives back the same elements, but in random order. The array is modified destructively.
permute()
int Array.search_array(array arr, string|function|int fun, mixed ... args)
search_array() works like map() , only it returns the index of the first call that returnes true instead.
If no call returns true, -1 is returned.
sum() , map()
array Array.sum_arrays(function(mixed ... :mixed) sum, array ... args)
Applies the function sum columnwise on the elements in the provided arrays. E.g. sum_array(`+,a,b,c) does the same as `+(a[*],b[*],c[*]).
array Array.sort_array(array arr, function|void cmp, mixed ... args)
This function sorts the array arr after a compare-function cmp which takes two arguments and should return 1 if the first argument is larger then the second. Returns the sorted array - arr is not sorted destructively.
The remaining arguments args will be sent as 3rd, 4th etc. argument to cmp .
If cmp is omitted, `>() is used instead.
map() , sort() , `>() , dwim_sort_func , lyskom_sort_func
int Array.dwim_sort_func(string a, string b)
Sort without respect to number formatting (most notably leading zeroes).
int Array.lyskom_sort_func(string a, string b)
Sort comparison function that does not care about case, nor about the contents of any parts of the string enclosed with '()'
Example: "Foo (bar)" is given the same weight as "foo (really!)"
array Array.flatten(array a)
Flatten a multi-dimensional array to a one-dimensional array.
mixed Array.sum(array a)
Sum the elements of an array using `+
array Array.uniq2(array a)
Perform the same action as the Unix uniq command on an array, that is, fold consecutive occurrences of the same element into a single element of the result array:
aabbbcaababb -> abcabab.
See also the uniq function.
array Array.arrayify(void|array|mixed x)
Make an array of the argument, if it isn't already. A zero_type argument gives the empty array. This is useful when something is either an array or a basic datatype, for instance in headers from the MIME module or Protocols.HTTP.Server.
Result depends of the argument type:
arrayify(x) => x
arrayify(x) => ({})
arrayify(x) => ({ x })
int Array.oid_sort_func(string a0, string b0)
Sort with care of numerical sort for OID values: "1.2.1" before "1.11.1"
array(array(array)) Array.greedy_diff(array from, array to)
Like Array.diff , but tries to generate bigger continuous chunks of the
differences, instead of maximizing the number of difference chunks. More
specifically, greedy_diff optimizes the cases where Array.diff returns
({ ..., A, Z, B, ({}), C, ... })
into the somewhat shorter diff arrays
({ ..., A, X, B, Y+B, C, ... })
({ ..., A, Z, B+C, ... })
({ ..., A, X+B+Y, B+C, ... })
int Array.count(array|mapping|multiset haystack, mixed needle)
mapping(mixed:int) Array.count(array|mapping|multiset haystack)
Returns the number of occurrences of needle in haystack . If the optional needle argument is omitted, count instead works similar to the unix command sort|uniq -c, returning a mapping with the number of occurrences of each element in haystack . For array or mapping haystack s, it's the values that are counted, for multisets the indices, as you'd expect.
String.count , search , has_value
array Array.common_prefix(array(array) arrs)
Find the longest common prefix from an array of arrays.
String.common_prefix
Module Function |
string Function.defined(function fun)
Returns a string with filename and linenumber where fun was defined.
Returns 0 (zero) when no line can be found, e.g. for builtin functions and functions in destructed objects.
mixed Function.splice_call(array args, function f, mixed|void ... extra)
Calls the given function with the args array plus the optional extra arguments as its arguments and returns the result.
Most useful in conjunction with map , and particularly in combination with sscanf with "...%{...%}..." scan strings (which indeed was what it was invented for in the first place).
The first arguments the function f expects
The function to apply the arguments on
Optional extra arguments to send to f
Whatever the supplied function f returns
class Product(string name, string version) { string _sprintf() { return sprintf("Product(%s/%s)", name, version); } } map(({ ({ "pike", "7.1.11" }), ({ "whitefish", "0.1" }) }), Function.splice_call, Product); ({ /* 2 elements */ Product(pike/7.1.11), Product(whitefish/0.1) })
Module Program |
array(program) Program.inherit_list(program p)
Returns an array with the programs that p has inherited.
array(program) Program.all_inherits(program p)
Document this function.
array Program.inherit_tree(program p)
Recursively builds a inheritance tree by fetching programs inheritance lists.
Returns an array with programs or arrays as elements.
> class a{} > class b{} > class c{ inherit a; } > class d{ inherit b; inherit c; } > Program.inherit_tree(d); Result: ({ /* 3 elements */ d, ({ /* 1 element */ program }), ({ /* 2 elements */ c, ({ /* 1 element */ program }) }) })
int Program.implements(program prog, program api)
Returns 1 if prog implements api .
int Program.inherits(program child, program parent)
Returns 1 if child has inherited parent .
string Program.defined(program p)
Returns a string with filename and linenumber describing where the program p was defined.
The returned string is of the format "filename:linenumber".
If it cannot be determined where the program was defined, 0 (zero) will be returned.
Module ADT |
CLASS ADT.Priority_queue |
inherit .Heap : Heap
mixed push(int pri, mixed val)
Document this function
void adjust_pri(mixed handle, int new_pri)
Document this function
mixed pop()
Document this function
CLASS ADT.Heap |
void push(mixed value)
Document this function
void adjust(mixed value)
Document this function
mixed top()
Document this function
int size()
Document this function
CLASS ADT.History |
A history is a stack where you can only push entries. When the stack has reached a certain size the oldest entries are removed on every push. Other proposed names for this data type is leaking stack and table (where you push objects onto the table in one end and objects are falling off the table in the other.
void ADT.History(int max_size)
max_size is the maximum number of entries that can reside in the history at the same time.
void set_no_adjacent_duplicates(int(0..1) i)
Change how the History object should treat two identical values in a row. If 1 than only unique values are allowed after each other.
query_no_adjacent_duplicates
int(0..1) query_no_adjacent_duplicates()
Tells if the History object allows adjacent equal values. 1 means that only uniqe values are allowed adter each other.
set_no_adjacent_duplicates
void push(mixed value)
Push a new value into the history.
int _sizeof()
A sizeof operation on this object returns the number of elements currently in the history, e.g. <= the current max size.
int get_maxsize()
Returns the maximum number of values in the history
set_maxsize
int get_latest_entry_num()
Returns the absolute sequence number of the latest result inserted into the history.
int get_first_entry_num()
Returns the absolute sequence number of the oldest result still in the history. Returns 0 if there are no results in the history.
mixed `[](int i)
Get a value from the history as if it was an array, e.g. both positive and negative numbers may be used. The positive numbers are however offset with 1, so [1] is the first entry in the history and [-1] is the last.
void `[]=(int i, mixed value)
Overwrite one value in the history. The history position may be identified either by positive or negative offset, like `[] .
void set_maxsize(int _maxsize)
Set the maximume number of entries that can be stored in the history simultaneous.
get_maxsize
void flush()
Empties the history. All entries in the history are removed, to allow garbage collect to remove them. The entry sequence counter is not reset.
array(int) _indices()
Returns the index numbers of the history entries available.
array _values()
Returns the values of the available history entries.
CLASS ADT.Queue |
A simple FIFO queue.
void ADT.Queue(mixed ... args)
Creates a queue with the initial items args in it.
void write(mixed item)
void put(mixed item)
Adds the item to the queue.
mixed read()
mixed get()
Returns the next element from the queue.
mixed peek()
Returns the next element from the queue without removing it from the queue.
int(0..1) is_empty()
Returns true if the queue is empty, otherwise zero.
void flush()
Empties the queue.
mixed cast(string to)
It is possible to cast ADT.Queue to an array.
CLASS ADT.Stack |
This class implements a simple stack. Instead of adding and removing elements to an array, and thus making it vary in size for every push and pop operation, this stack tries to keep the stack size constant. If however the stack risks to overflow, it will allocate double its current size, i.e. pushing an element on an full 32 slot stack will result in a 64 slot stack with 33 elements.
void push(mixed val)
Push an element on the top of the stack.
mixed top()
Returns the top element from the stack, without popping it.
Throws an error if called on an empty stack.
void quick_pop(void|int val)
Pops val entries from the stack, or one entry if no value is given. The popped entries are not actually freed, only the stack pointer is moved.
mixed pop(void|int val)
Pops and returns entry val from the stack, counting from the top. If no value is given the top element is popped and returned. All popped entries are freed from the stack.
void reset(int|void initial_size)
Empties the stack, resets the stack pointer and shrinks the stack size to the given value or 32 if none is given.
create
void ADT.Stack(int|void initial_size)
An initial stack size can be given when a stack is cloned. The default value is 32.
void set_stack(array stack)
Sets the stacks content to the provided array.
int _sizeof()
sizeof on a stack returns the number of entries in the stack.
array _values()
values on a stack returns all the entries in the stack, in order.
this_program `+(this_program s)
A stack added with another stack yields a third a third stack will all the stack elements from the two first stacks.
Module ADT.Relation |
CLASS ADT.Relation.Binary |
mixed contains(mixed left, mixed right)
Return true/false: does the relation "left R right " exist?
mixed `()(mixed left, mixed right)
Does the same as the contains function: returns true if the relation "left R right " exists, and otherwise false.
mixed add(mixed left, mixed right)
Adds "left R right " as a member of the relation. Returns the same relation.
mixed remove(mixed left, mixed right)
Removes "left R right " as a member of the relation. Returns the same relation.
array map(function f)
Maps every entry in the relation. The function f gets two arguments: the left and the right relation value. Returns an array with the return values of f for each and every mapped entry.
Note: since the entries in the relation are not ordered, the returned array will have its elements in no particular order. If you need to know which relation entry produced which result in the array, you have to make that information part of the value that f returns.
object filter(function f)
Filters the entries in the relation, and returns a relation with all those entries for which the filtering function f returned true. The function f gets two arguments: the left and the right value for every entry in the relation.
object filter_destructively(function f)
Filters the entries in the relation destructively, removing all entries for which the filtering function f returns false. The function f gets two arguments: the left and the right value for each entry in the relation.
mixed _sizeof()
Returns the number of relation entries in the relation. (Or with other words: the number of relations in the relation set.)
mixed `<=(object rel)
The expression `rel1 <= rel2' returns true if every relation entry in rel1 is also present in rel2.
mixed `&(mixed rel)
The expression `rel1 & rel2' returns a new relation which has those and only those relation entries that are present in both rel1 and rel2.
mixed `|(mixed rel)
The expression `rel1 | rel2' returns a new relation which has all the relation entries present in rel1, or rel2, or both.
mixed `-(mixed rel)
The expression `rel1 - rel2' returns a new relation which has those and only those relation entries that are present in rel1 and not present in rel2.
object make_symmetric()
Makes the relation symmetric, i.e. makes sure that if xRy is part of the relation set, then yRx should also be a part of the relation set.
array find_shortest_path(mixed from, mixed to, void|multiset avoiding)
Assuming the relation's domain and range sets are equal, and that the relation xRy means "there is a path from node x to node y", find_shortest_path attempts to find a path with a minimum number of steps from one given node to another. The path is returned as an array of nodes (including the starting and ending node), or 0 if no path was found. If several equally short paths exist, one of them will be chosen pseudorandomly.
Trying to find a path from a node to itself will always succeed, returning an array of one element: the node itself. (Or in other words, a path with no steps, only a starting/ending point).
The argument avoiding is either 0 (or omitted), or a multiset of nodes that must not be part of the path.
mixed get_id()
Return the ID value which was given as first argument to create().
CLASS ADT.Relation.Binary._get_iterator |
An iterator which makes all the left/right entities in the relation available as index/value pairs.
Module ADT.Table |
ADT.Table is a generic module for manipulating tables.
Each table contains one or several columns. Each column is associated with a name, the column name. Optionally, one can provide a column type. The Table module can do a number of operations on a given table, like computing the sum of a column, grouping, sorting etc.
All column references are case insensitive. A column can be referred to by its position (starting from zero). All operations are non-destructive. That means that a new table object will be returned after, for example, a sort.
CLASS ADT.Table.table |
The table base-class.
string encode()
This method returns a binary string representation of the table. It is useful when one wants to store a the table, for example in a file.
object decode(string s)
This method returns a table object from a binary string representation of a table, as returned by encode() .
array(string) _indices()
This method returns the column names for the table. The case used when the table was created will be returned.
array(array) _values()
This method returns the contents of a table as a two dimensional array. The format is an array of rows. Each row is an array of columns.
int _sizeof()
This method returns the number of rows in the table.
object reverse()
This method reverses the rows of the table and returns a new table object.
array col(int|string column)
This method returns the contents of a given column as an array.
array row(int row_number)
This method returns the contents of a given row as an array.
array `[](int|string column)
Same as col() .
int `==(object table)
This method compares two tables. They are equal if the contents of the tables and the column names are equal. The column name comparison is case insensitive.
object append_bottom(object table)
This method appends two tables. The table given as an argument will be added at the bottom of the current table. Note, the column names must be equal. The column name comparison is case insensitive.
object append_right(object table)
This method appends two tables. The table given as an argument will be added on the right side of the current table. Note that the number of rows in both tables must be equal.
object select(int|string ... columns)
This method returns a new table object with the selected columns only.
object remove(int|string ... columns)
Like select() , but the given columns will not be in the resulting table.
object where(array(int|string)|int|string columns, function f, mixed ... args)
This method calls the function for each row. If the function returns zero, the row will be thrown away. If the function returns something non-zero, the row will be kept. The result will be returned as a new table object.
object group(mapping(int|string:function)|function f, mixed ... args)
This method calls the function f for each column each time a non uniqe row will be joined. The table will be grouped by the columns not listed. The result will be returned as a new table object.
object sum(int|string ... columns)
This method sums all equal rows. The table will be grouped by the columns not listed. The result will be returned as a new table object.
object distinct(int|string ... columns)
This method groups by the given columns and returns a table with only unique rows. When no columns are given, all rows will be unique. A new table object will be returned.
object map(function f, array(int|string)|int|string columns, mixed ... args)
This method calls the function f for all rows in the table. The value returned will replace the values in the columns given as argument to map. If the function returns an array, several columns will be replaced. Otherwise the first column will be replaced. The result will be returned as a new table object.
object sort(int|string ... columns)
This method sorts the table in ascendent order on one or several columns and returns a new table object. The left most column is sorted last. Note that the sort is stable.
rsort()
object rsort(int|string ... columns)
Like sort() , but in descending order.
object limit(int n)
This method truncates the table to the first n rows and returns a new object.
object rename(string|int from, string to)
This method renames the column named from to to and returns a new table object. Note that from can be the column position.
mapping type(int|string column, void|mapping type)
This method gives the type for the given column .
If a second argument is given, the old type will be replaced with type . The column type is only used when the table is displayed. The format is as specified in create() .
void ADT.Table.table(array(array) table, array(string) column_names, array(mapping(string:string))|void column_types)
The ADT.Table.table class takes two or three arguments:
The first argument is a two-dimensional array consisting of one array of columns per row. All rows must have the same number of columns as specified in column_names .
This argument is an array of column names associated with each column in the table. References by column name are case insensitive. The case used in column_names will be used when the table is displayed. A column can also be referred to by its position, starting from zero.
This is an optional array of mappings. The column type information is only used when displaying the table. Currently, only the keyword "type" is recognized. The type can be specified as "text" or "num" (numerical). Text columns are left adjusted, whereas numerical columns are right adjusted. If a mapping in the array is 0 (zero), it will be assumed to be a text column. If column_types is omitted, all columns will displayed as text.
See ADT.Table.ASCII.encode() on how to display a table.
ADT.Table.ASCII.encode()
Module ADT.Table.ASCII |
string ADT.Table.ASCII.encode(object table, void|mapping options)
This method returns a table represented in ASCII suitable for human eyes. options is an optional mapping. If the keyword "indent" is used with a number, the table will be indented with that number of space characters.