MapleTableAlloc - create a table in external code
MapleTableAssign - assign into a table in external code
MapleTableSelect - select from a table in external code
MapleTableDelete - delete an element in a table in external code
MapleTableHasEntry - test if an element exists in a table in external code
|
Calling Sequence
|
|
MapleTableAlloc(kv)
MapleTableAssign(kv, table, ind, val)
MapleTableSelect(kv, table, ind)
MapleTableDelete(kv, table, ind)
MapleTableHasEntry(kv, table, ind)
|
|
Parameters
|
|
kv
|
-
|
kernel handle of type MKernelVector
|
table
|
-
|
Maple table object
|
ind
|
-
|
index or key that maps to the data in a table
|
val
|
-
|
value to assign into the table
|
|
|
|
|
Description
|
|
•
|
MapleTableAlloc creates a new table object. Tables are dynamic and grow as needed, so, unlike MapleListAlloc, no size parameter is needed.
|
•
|
MapleTableAssign sets the element at index ind of the table to the value val, that is, table[ind] := val. An index can be any valid Maple object. Elements can be removed and inserted from tables at any time (unlike MapleListAssign, which can only be used immediately after creating a list).
|
•
|
MapleTableSelect retrieves the element at index ind of the table. If no element exists at the index ind, then NULL is returned.
|
•
|
MapleTableDelete removes the element at index ind of the table. If no element exists at the index ind, the table is unmodified.
|
•
|
MapleTableHasEntry returns TRUE if there exists an element at index ind of the table, and FALSE if nothing exists at that index.
|
|
|
Examples
|
|
#include <string.h>
|
#include "maplec.h"
|
ALGEB M_DECL MyDictionary( MKernelVector kv, ALGEB *args )
|
{
|
ALGEB tab, val;
|
char *code;
|
M_INT argc;
|
M_BOOL r;
|
argc = MapleNumArgs(kv,(ALGEB)args);
|
if( argc < 1 ) {
|
MapleRaiseError(kv,"at least one argument expected");
|
return( NULL );
|
}
|
if( !IsMapleString(kv,args[1]) ) {
|
MapleRaiseError(kv,"string expected");
|
return( NULL );
|
}
|
code = MapleToString(kv,args[1]);
|
if( strcmp(code,"create") == 0 ) {
|
return( MapleTableAlloc(kv) );
|
}
|
if( argc < 3 ) {
|
MapleRaiseError(kv,
|
"at least 3 arguments expected for this operation");
|
return( NULL );
|
}
|
if( !IsMapleTable(kv,args[2]) ) {
|
MapleRaiseError(kv,"table expected");
|
return( NULL );
|
}
|
tab = args[2];
|
if( strcmp(code,"insert") == 0 ) {
|
if( argc != 4 ) {
|
MapleRaiseError(kv,"4 arguments expected for insert");
|
return( NULL );
|
}
|
MapleTableAssign(kv,tab,args[3],args[4]);
|
return( ToMapleBoolean(kv,TRUE) );
|
}
|
else if( strcmp(code,"lookup") == 0 ) {
|
if( (val=MapleTableSelect(kv,tab,args[3])) == NULL )
|
return( ToMapleBoolean(kv,-1) );
|
else
|
return( val );
|
}
|
else if( strcmp(code,"remove") == 0 ) {
|
r = MapleTableHasEntry(kv,tab,args[3]);
|
MapleTableDelete(kv,tab,args[3]);
|
return( ToMapleBoolean(kv,r) );
|
}
|
else {
|
MapleRaiseError1(kv,"unrecognized option %1",args[1]);
|
return( NULL );
|
}
|
}
|
|
|
Execute the external function from Maple.
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
|
|