summaryrefslogtreecommitdiffstatshomepage
path: root/py/map.c
Commit message (Collapse)AuthorAge
* py/map: Change mp_uint_t to size_t where appropriate.Damien George2017-02-08
| | | | | | | | The internal map/set functions now use size_t exclusively for computing addresses. size_t is enough to reach all of available memory when computing addresses so is the right type to use. In particular, for nanbox builds it saves quite a bit of code size and RAM compared to the original use of mp_uint_t (which is 64-bits on nanbox builds).
* py: Declare constant data as properly constant.Damien George2016-05-20
| | | | | Otherwise some compilers (eg without optimisation) will put this read-only data in RAM instead of ROM.
* py/map: Change hash-table allocation policy to be less aggressive.Damien George2016-04-15
| | | | | | | | | | 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.
* py/map: Prevent map resize failure from destroying map.Stephen Kyle2016-04-01
|
* py/map: In map lookup, check for fixed map independent of ordered map.Damien George2015-12-31
| | | | | It's possible to have a fixed map that is properly hashed (ie not simply ordered).
* py/map: Add fast-path for hashing of map index when it is a qstr.Damien George2015-12-26
| | | | | | | | 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.
* py: Use MP_OBJ_NULL instead of NULL when appropriate.Damien George2015-11-20
|
* py/map: Store key/value in earliest possible slot in hash table.Damien George2015-11-19
| | | | | | | | 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.
* py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George2015-05-12
| | | | | | | | | | | | | | 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__".
* py: Some trivial cosmetic changes, for code style consistency.Damien George2015-04-04
|
* py: Clarify API for map/set lookup when removing&adding at once.Damien George2015-03-20
| | | | Addresses issue #1160.
* py: Implement core of OrderedDict type.Paul Sokolovsky2015-03-20
| | | | | | | | | | | | 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.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Allow to properly disable builtin "set" object.Damien George2014-12-27
| | | | | | | | 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.
* map: Add empty fixed map.Paul Sokolovsky2014-11-27
| | | | | Useful when need to call kw-receiving functions without any keywords from C, etc.
* py: Fix some macros defines; cleanup some includes.Damien George2014-11-05
|
* py: Make map, dict, set use mp_int_t/mp_uint_t exclusively.Damien George2014-08-30
| | | | Part of code cleanup, towards resolving issue #50.
* Rename machine_(u)int_t to mp_(u)int_t.Damien George2014-07-03
| | | | See discussion in issue #50.
* py: Include mpconfig.h before all other includes.Paul Sokolovsky2014-06-21
| | | | | | It defines types used by all other headers. Fixes #691.
* Add license header to (almost) all files.Damien George2014-05-03
| | | | | | | 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/.
* py: Fix bug in map lookup of interned string vs non-interned.Damien George2014-04-28
| | | | | | | Had choice of either interning or forcing full equality comparison, and chose latter. See comments in mp_map_lookup. Addresses issue #523.
* py: Revert revert for allocation policy of set hash table.Damien George2014-04-07
|
* py: Revert change to allocation policy for mp_set_t.Damien George2014-04-07
| | | | Seems that this fixes all set tests.
* py: Fix dict.copy() and low-level map/set allocation.Paul Sokolovsky2014-04-06
| | | | | | | | | | 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).
* py: Make mp_map_lookup not allocate memory on removal.Damien George2014-04-05
|
* py: Change module globals from mp_map_t* to mp_obj_dict_t*.Damien George2014-04-05
| | | | | | Towards addressing issue #424. Had a small increase to ROM usage (order 60 bytes).
* py: Fix delete operation on map/dict and set objects.Damien George2014-04-05
| | | | | | 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.
* map: When removing a key, don't NULL the entry, but mark as deleted.Paul Sokolovsky2014-04-05
| | | | | | | | | | 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.
* map: Add mp_map_dump() (#ifdef'ed) to be handy when debugging maps.Paul Sokolovsky2014-04-05
|
* Merge map.h into obj.h.Damien George2014-03-30
| | | | | | 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.
* py: Clean up includes.xbe2014-03-17
| | | | Remove unnecessary includes. Add includes that improve portability.
* Replace global "static" -> "STATIC", to allow "analysis builds". Part 2.Paul Sokolovsky2014-02-12
|
* py: Allow mp_map_t to be initialised by a fixed-size, const table.Damien George2014-02-08
| | | | This allows keyword maps to be created directly from stack data.
* Add mp_map_deinit() & mp_map_free() to finalize maps.Paul Sokolovsky2014-01-25
| | | | mp_map_deinit() finalizes static map, mp_map_free() - dynamic.
* Revamp qstrs: they now include length and hash.Damien George2014-01-21
| | | | | Can now have null bytes in strings. Can define ROM qstrs per port using qstrdefsport.h
* Implemented set.removeJohn R. Lenton2014-01-12
|
* Implemented set.discardJohn R. Lenton2014-01-12
|
* Implemented set.clearJohn R. Lenton2014-01-12
|
* py: Stuff qstr in object pointer; keys for mp_map_t are now always mp_obj_t.Damien George2014-01-08
|
* Added dict.setdefaultJohn R. Lenton2014-01-07
|
* implemented dict.popJohn R. Lenton2014-01-07
|
* Added dict.clear.John R. Lenton2014-01-07
| | | | Added 0 to the list of primes. Funky primes, these.
* Change memory allocation API to require size for free and realloc.Damien2013-12-29
|
* Change object representation from 1 big union to individual structs.Damien2013-12-21
| | | | | | | | | | 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).
* py: split runtime into map, obj, builtin.Damien2013-12-17