zoukankan      html  css  js  c++  java
  • Python的dict数据结构

    1.PyDictEntry数据结构

    1 typedef struct {
    2     /* Cached hash code of me_key.  Note that hash codes are C longs.
    3      * We have to use Py_ssize_t instead because dict_popitem() abuses
    4      * me_hash to hold a search finger.
    5      */
    6     Py_ssize_t me_hash;
    7     PyObject *me_key;
    8     PyObject *me_value;
    9 } PyDictEntry;

    2._dictobject数据结构

     1 typedef struct _dictobject PyDictObject;
     2 struct _dictobject {
     3     PyObject_HEAD
     4     Py_ssize_t ma_fill;  /* # Active + # Dummy */
     5     Py_ssize_t ma_used;  /* # Active */
     6 
     7     /* The table contains ma_mask + 1 slots, and that's a power of 2.
     8      * We store the mask instead of the size because the mask is more
     9      * frequently needed.
    10      */
    11     Py_ssize_t ma_mask;
    12 
    13     /* ma_table points to ma_smalltable for small tables, else to
    14      * additional malloc'ed memory.  ma_table is never NULL!  This rule
    15      * saves repeated runtime null-tests in the workhorse getitem and
    16      * setitem calls.
    17      */
    18     PyDictEntry *ma_table;
    19     PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
    20     PyDictEntry ma_smalltable[PyDict_MINSIZE];
    21 };

    可以看出来dict使用的是hash数据结构!

  • 相关阅读:
    javascript数组/对象数组的深浅拷贝问题
    Vue packages version mismatch
    关于Echarts的使用和遇到的问题
    webpack 打包 todolist 应用
    Js正则学习笔记
    Vue项目多域名跨域
    Vuex的简单应用
    css3实现饼状图进度及环形进度条
    浏览器缓存机制
    去除滚动条
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/4631245.html
Copyright © 2011-2022 走看看