Python中的Dict对象(Python 源码剖析第五章)

Python字典内部结构解析
ExpandedBlockStart.gif 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;
10 

 

ExpandedBlockStart.gif PyDictObject
 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  };  

转载于:https://www.cnblogs.com/zhtf2014/archive/2010/11/15/1877986.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值