summaryrefslogtreecommitdiff
path: root/py/map.c
AgeCommit message (Collapse)Author
2016-04-15py/map: Change hash-table allocation policy to be less aggressive.Damien George
Small hash tables (eg those used in user class instances that only have a few members) now only use the minimum amount of memory necessary to hold the key/value pairs. This can reduce performance for instances that have many members (because then there are many reallocations/rehashings of the table), but helps to conserve memory. See issue #1760.
2016-04-01py/map: Prevent map resize failure from destroying map.Stephen Kyle
2015-12-31py/map: In map lookup, check for fixed map independent of ordered map.Damien George
It's possible to have a fixed map that is properly hashed (ie not simply ordered).
2015-12-26py/map: Add fast-path for hashing of map index when it is a qstr.Damien George
Map indicies are most commonly a qstr, and adding a fast-path for hashing of a qstr increases overall performance of the runtime. On pyboard there is a 4% improvement in the pystone benchmark for a cost of 20 bytes of code size. It's about a 2% improvement on unix.
2015-11-20py: Use MP_OBJ_NULL instead of NULL when appropriate.Damien George
2015-11-19py/map: Store key/value in earliest possible slot in hash table.Damien George
This change makes the code behave how it was supposed to work when first written. The avail_slot variable is set to the first free slot when looking for a key (which would come from deleting an entry). So it's more efficient (for subsequent lookups) to insert a new key into such a slot, rather than the very last slot that was searched.
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
2015-04-04py: Some trivial cosmetic changes, for code style consistency.Damien George
2015-03-20py: Clarify API for map/set lookup when removing&adding at once.Damien George
Addresses issue #1160.
2015-03-20py: Implement core of OrderedDict type.Paul Sokolovsky
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.
2015-01-16py, unix: Allow to compile with -Wsign-compare.Damien George
See issue #699.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-27py: Allow to properly disable builtin "set" object.Damien George
This patch makes MICROPY_PY_BUILTINS_SET compile-time option fully disable the builtin set object (when set to 0). This includes removing set constructor/comprehension from the grammar, the compiler and the emitters. Now, enabling set costs 8168 bytes on unix x64, and 3576 bytes on stmhal.
2014-11-27map: Add empty fixed map.Paul Sokolovsky
Useful when need to call kw-receiving functions without any keywords from C, etc.
2014-11-05py: Fix some macros defines; cleanup some includes.Damien George
2014-08-30py: Make map, dict, set use mp_int_t/mp_uint_t exclusively.Damien George
Part of code cleanup, towards resolving issue #50.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-21py: Include mpconfig.h before all other includes.Paul Sokolovsky
It defines types used by all other headers. Fixes #691.
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-04-28py: Fix bug in map lookup of interned string vs non-interned.Damien George
Had choice of either interning or forcing full equality comparison, and chose latter. See comments in mp_map_lookup. Addresses issue #523.
2014-04-07py: Revert revert for allocation policy of set hash table.Damien George
2014-04-07py: Revert change to allocation policy for mp_set_t.Damien George
Seems that this fixes all set tests.
2014-04-06py: Fix dict.copy() and low-level map/set allocation.Paul Sokolovsky
Two things: 1) set flags in copy properly; make mp_map_init() not be too smart and do something with requested alloc size. Policy of using prime numbers for alloc size is high-level policy which should be applied at corresponding high levels. Low-level functions should just do what they're asked to, because they don't have enough context to be smarter than that. For example, munging with alloc size of course breaks dict copying (as changing sizes requires rehashing).
2014-04-05py: Make mp_map_lookup not allocate memory on removal.Damien George
2014-04-05py: Change module globals from mp_map_t* to mp_obj_dict_t*.Damien George
Towards addressing issue #424. Had a small increase to ROM usage (order 60 bytes).
2014-04-05py: Fix delete operation on map/dict and set objects.Damien George
Hash table can now be completely full (ie now NULL entry) before a resize is triggered. Use sentinel value to indicate delete entry in the table.
2014-04-05map: When removing a key, don't NULL the entry, but mark as deleted.Paul Sokolovsky
When searching next time, such entry should be just skipped, not terminate the search. It's known that marking techique is not efficient at the presense of many removes, but namespace usage should not require many deletes, and as for user dictionaries - well, open addressing map table with linear rehashing and load factor of ~1 is not particularly efficient at all ;-). TODO: May consider "shift other entries in cluster" approach as an alternative.
2014-04-05map: Add mp_map_dump() (#ifdef'ed) to be handy when debugging maps.Paul Sokolovsky
2014-03-30Merge map.h into obj.h.Damien George
Pretty much everyone needs to include map.h, since it's such an integral part of the Micro Python object implementation. Thus, the definitions are now in obj.h instead. map.h is removed.
2014-03-17py: Clean up includes.xbe
Remove unnecessary includes. Add includes that improve portability.
2014-02-12Replace global "static" -> "STATIC", to allow "analysis builds". Part 2.Paul Sokolovsky
2014-02-08py: Allow mp_map_t to be initialised by a fixed-size, const table.Damien George
This allows keyword maps to be created directly from stack data.
2014-01-25Add mp_map_deinit() & mp_map_free() to finalize maps.Paul Sokolovsky
mp_map_deinit() finalizes static map, mp_map_free() - dynamic.
2014-01-21Revamp qstrs: they now include length and hash.Damien George
Can now have null bytes in strings. Can define ROM qstrs per port using qstrdefsport.h
2014-01-12Implemented set.removeJohn R. Lenton
2014-01-12Implemented set.discardJohn R. Lenton
2014-01-12Implemented set.clearJohn R. Lenton
2014-01-08py: Stuff qstr in object pointer; keys for mp_map_t are now always mp_obj_t.Damien George
2014-01-07Added dict.setdefaultJohn R. Lenton
2014-01-07implemented dict.popJohn R. Lenton
2014-01-07Added dict.clear.John R. Lenton
Added 0 to the list of primes. Funky primes, these.
2013-12-29Change memory allocation API to require size for free and realloc.Damien
2013-12-21Change object representation from 1 big union to individual structs.Damien
A big change. Micro Python objects are allocated as individual structs with the first element being a pointer to the type information (which is itself an object). This scheme follows CPython. Much more flexible, not necessarily slower, uses same heap memory, and can allocate objects statically. Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-17py: split runtime into map, obj, builtin.Damien