Skip to content
Snippets Groups Projects
Select Git revision
  • fc6222fd60b2a0a612d5f8ec79e5ea6c0739cce1
  • master default protected
  • esp32-nimble-wiki
  • rahix/hw-lock-new-mutex
  • dx/somewhat-more-dynamic-config
  • schneider/sdk-0.2.1-7
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

gen-qstr.sh

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    map.c 15.06 KiB
    /*
     * This file is part of the Micro Python project, http://micropython.org/
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2013, 2014 Damien P. George
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
    
    #include <stdint.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    #include "py/mpconfig.h"
    #include "py/misc.h"
    #include "py/runtime0.h"
    #include "py/runtime.h"
    
    // Fixed empty map. Useful when need to call kw-receiving functions
    // without any keywords from C, etc.
    const mp_map_t mp_const_empty_map = {
        .all_keys_are_qstrs = 0,
        .is_fixed = 1,
        .is_ordered = 1,
        .used = 0,
        .alloc = 0,
        .table = NULL,
    };
    
    // This table of sizes is used to control the growth of hash tables.
    // The first set of sizes are chosen so the allocation fits exactly in a
    // 4-word GC block, and it's not so important for these small values to be
    // prime.  The latter sizes are prime and increase at an increasing rate.
    STATIC uint16_t hash_allocation_sizes[] = {
        0, 2, 4, 6, 8, 10, 12, // +2
        17, 23, 29, 37, 47, 59, 73, // *1.25
        97, 127, 167, 223, 293, 389, 521, 691, 919, 1223, 1627, 2161, // *1.33
        3229, 4831, 7243, 10861, 16273, 24407, 36607, 54907, // *1.5
    };
    
    STATIC mp_uint_t get_hash_alloc_greater_or_equal_to(mp_uint_t x) {
        for (size_t i = 0; i < MP_ARRAY_SIZE(hash_allocation_sizes); i++) {
            if (hash_allocation_sizes[i] >= x) {
                return hash_allocation_sizes[i];
            }
        }
        // ran out of primes in the table!
        // return something sensible, at least make it odd
        return (x + x / 2) | 1;
    }
    
    /******************************************************************************/