python-on-a-chip online compiler

Dependencies:   mbed TSI

Embed: (wiki syntax)

« Back to documentation index

dict.h File Reference

dict.h File Reference

Dict Object Type. More...

Go to the source code of this file.

Data Structures

struct  PmDict_s
 Dict. More...

Typedefs

typedef struct PmDict_s PmDict_t
 Dict.

Functions

PmReturn_t dict_clear (pPmObj_t pdict)
 Clears the contents of a dict.
PmReturn_t dict_getItem (pPmObj_t pdict, pPmObj_t pkey, pPmObj_t *r_pobj)
 Gets the value in the dict using the given key.
PmReturn_t dict_delItem (pPmObj_t pdict, pPmObj_t pkey)
 Removes a key and value from the dict.
PmReturn_t dict_new (pPmObj_t *r_pdict)
 Allocates space for a new Dict.
PmReturn_t dict_setItem (pPmObj_t pdict, pPmObj_t pkey, pPmObj_t pval)
 Sets a value in the dict using the given key.
PmReturn_t dict_print (pPmObj_t pdict)
 Prints out a dict.
PmReturn_t dict_update (pPmObj_t pdestdict, pPmObj_t psourcedict, uint8_t omit_underscored)
 Updates the destination dict with the key,value pairs from the source dict.
int8_t dict_compare (pPmObj_t d1, pPmObj_t d2)
 Returns C_SAME if the two given dictionaries have the same contents.

Detailed Description

Dict Object Type.

Dict object type header.

Definition in file dict.h.


Typedef Documentation

typedef struct PmDict_s PmDict_t

Dict.

Contains ptr to two seglists, one for keys, the other for values; and a length, the number of key/value pairs.


Function Documentation

PmReturn_t dict_clear ( pPmObj_t  pdict )

Clears the contents of a dict.

after this operation, the dict should in the same state as if it were just created using dict_new().

Parameters:
pdictptr to dict to clear.
Returns:
nothing

Definition at line 48 of file dict.c.

int8_t dict_compare ( pPmObj_t  d1,
pPmObj_t  d2 
)

Returns C_SAME if the two given dictionaries have the same contents.

Parameters:
d1ptr to a dictionary object
d2ptr to another dictionary object
Returns:
C_DIFFER or C_SAME

Definition at line 337 of file dict.c.

PmReturn_t dict_delItem ( pPmObj_t  pdict,
pPmObj_t  pkey 
)

Removes a key and value from the dict.

Throws TypeError if pdict is not a dict. Throws KeyError if pkey does not exist in pdict.

Parameters:
pdictPtr to dict to search
pkeyPtr to key obj
Returns:
Return status

Definition at line 208 of file dict.c.

PmReturn_t dict_getItem ( pPmObj_t  pdict,
pPmObj_t  pkey,
pPmObj_t r_pobj 
)

Gets the value in the dict using the given key.

Parameters:
pdictptr to dict to search
pkeyptr to key obj
r_pobjReturn; addr of ptr to obj
Returns:
Return status

Definition at line 159 of file dict.c.

PmReturn_t dict_new ( pPmObj_t r_pdict )

Allocates space for a new Dict.

Return a pointer to the dict by reference.

Parameters:
r_pdictReturn; Addr of ptr to dict
Returns:
Return status

Definition at line 25 of file dict.c.

PmReturn_t dict_print ( pPmObj_t  pdict )

Prints out a dict.

Uses obj_print() to print elements.

Parameters:
pobjObject to print.
Returns:
Return status

Definition at line 242 of file dict.c.

PmReturn_t dict_setItem ( pPmObj_t  pdict,
pPmObj_t  pkey,
pPmObj_t  pval 
)

Sets a value in the dict using the given key.

If the dict already contains a matching key, the value is replaced; otherwise the new key,val pair is inserted at the front of the dict (for fast lookup). In the later case, the length of the dict is incremented.

Parameters:
pdictptr to dict in which (key,val) will go
pkeyptr to key obj
pvalptr to val obj
Returns:
Return status

Definition at line 89 of file dict.c.

PmReturn_t dict_update ( pPmObj_t  pdestdict,
pPmObj_t  psourcedict,
uint8_t  omit_underscored 
)

Updates the destination dict with the key,value pairs from the source dict.

Parameters:
pdestdictptr to destination dict in which key,val pairs will go
psourcedictptr to source dict which has all key,val pairs to copy
omit_underscoredBoolean set to true to omit key,val pairs where the key starts with an underscore '_'.
Returns:
Return status

Definition at line 290 of file dict.c.