MapleTableAlloc - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


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

Parameters

Description

Examples

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

• 

These functions can be used in external code with OpenMaple or define_external.

• 

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.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

dictDefineExternalMyDictionary&comma;dll&colon;

ddictcreate&colon;

dictinsert&comma;d&comma;Paul&comma;1&comma;2&comma;3

true

(1)

dictlookup&comma;d&comma;Paul

1&comma;2&comma;3

(2)

dictremove&comma;d&comma;Paul

true

(3)

dictlookup&comma;d&comma;Paul

FAIL

(4)

dictremove&comma;d&comma;Paul

false

(5)

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples