summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.h
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-03-18 01:25:04 +0200
committerDamien George <damien.p.george@gmail.com>2015-03-20 17:26:10 +0000
commit0ef01d0a75b8b2f48a72f0041e048a390b9e75b6 (patch)
tree2d32b82d34d026ac59b9724ea5323612bc09b67d /py/obj.h
parent1004535237e8edc5ec671ab8bea6fd2150139c54 (diff)
downloadmicropython-0ef01d0a75b8b2f48a72f0041e048a390b9e75b6.tar.gz
micropython-0ef01d0a75b8b2f48a72f0041e048a390b9e75b6.zip
py: Implement core of OrderedDict type.
Given that there's already support for "fixed table" maps, which are essentially ordered maps, the implementation of OrderedDict just extends "fixed table" maps by adding an "is ordered" flag and add/remove operations, and reuses 95% of objdict code, just making methods tolerant to both dict and OrderedDict. Some things are missing so far, like CPython-compatible repr and comparison. OrderedDict is Disabled by default; enabled on unix and stmhal ports.
Diffstat (limited to 'py/obj.h')
-rw-r--r--py/obj.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/py/obj.h b/py/obj.h
index c58b72f08a..3e2cd2a16f 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -109,7 +109,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_DEFINE_CONST_MAP(map_name, table_name) \
const mp_map_t map_name = { \
.all_keys_are_qstrs = 1, \
- .table_is_fixed_array = 1, \
+ .is_fixed = 1, \
+ .is_ordered = 1, \
.used = MP_ARRAY_SIZE(table_name), \
.alloc = MP_ARRAY_SIZE(table_name), \
.table = (mp_map_elem_t*)table_name, \
@@ -120,7 +121,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
.base = {&mp_type_dict}, \
.map = { \
.all_keys_are_qstrs = 1, \
- .table_is_fixed_array = 1, \
+ .is_fixed = 1, \
+ .is_ordered = 1, \
.used = MP_ARRAY_SIZE(table_name), \
.alloc = MP_ARRAY_SIZE(table_name), \
.table = (mp_map_elem_t*)table_name, \
@@ -150,8 +152,9 @@ typedef struct _mp_map_elem_t {
typedef struct _mp_map_t {
mp_uint_t all_keys_are_qstrs : 1;
- mp_uint_t table_is_fixed_array : 1;
- mp_uint_t used : (8 * sizeof(mp_uint_t) - 2);
+ mp_uint_t is_fixed : 1; // a fixed array that can't be modified; must also be ordered
+ mp_uint_t is_ordered : 1; // an ordered array
+ mp_uint_t used : (8 * sizeof(mp_uint_t) - 3);
mp_uint_t alloc;
mp_map_elem_t *table;
} mp_map_t;
@@ -327,6 +330,7 @@ extern const mp_obj_type_t mp_type_map; // map (the python builtin, not the dict
extern const mp_obj_type_t mp_type_enumerate;
extern const mp_obj_type_t mp_type_filter;
extern const mp_obj_type_t mp_type_dict;
+extern const mp_obj_type_t mp_type_ordereddict;
extern const mp_obj_type_t mp_type_range;
extern const mp_obj_type_t mp_type_set;
extern const mp_obj_type_t mp_type_frozenset;