diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-25 00:02:20 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-25 02:04:01 +0200 |
commit | 9a24a0465f4924ae1853a822d245af9e3a24fc2d (patch) | |
tree | 33e5c72ca9799f366d1b02e07a6244ae0b285fca /py | |
parent | fcd4ae827171717ea501bf833a6b6abd70edc5a3 (diff) | |
download | micropython-9a24a0465f4924ae1853a822d245af9e3a24fc2d.tar.gz micropython-9a24a0465f4924ae1853a822d245af9e3a24fc2d.zip |
Add mp_map_deinit() & mp_map_free() to finalize maps.
mp_map_deinit() finalizes static map, mp_map_free() - dynamic.
Diffstat (limited to 'py')
-rw-r--r-- | py/map.c | 11 | ||||
-rw-r--r-- | py/map.h | 2 |
2 files changed, 13 insertions, 0 deletions
@@ -40,6 +40,17 @@ mp_map_t *mp_map_new(int n) { return map; } +// Differentiate from mp_map_clear() - semantics is different +void mp_map_deinit(mp_map_t *map) { + m_del(mp_map_elem_t, map->table, map->alloc); + map->used = map->alloc = 0; +} + +void mp_map_free(mp_map_t *map) { + mp_map_deinit(map); + m_del_obj(mp_map_t, map); +} + void mp_map_clear(mp_map_t *map) { map->used = 0; map->all_keys_are_qstrs = 1; @@ -28,6 +28,8 @@ typedef enum _mp_map_lookup_kind_t { int get_doubling_prime_greater_or_equal_to(int x); void mp_map_init(mp_map_t *map, int n); mp_map_t *mp_map_new(int n); +void mp_map_deinit(mp_map_t *map); +void mp_map_free(mp_map_t *map); mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind); void mp_map_clear(mp_map_t *map); |