Python's DICT data structure

Source: Internet
Author: User

1.PyDictEntry Data structure

  typedef struct { 2 /* Cached hash code of ME_  Key. Note that hash codes is C longs.  3  * We have the use py_ssize_t instead because dict _popitem () Abuses  4  * Me_hash to hold a sear CH finger.  5  */ Py _ssize_t Me_hash;  7  pyobject *me_key;  8  pyobject *me_value;  9 } pydictentry;  

2._dictobject data structure

1 typedef struct _DICTOBJECT pydictobject;2 struct _dictobject {3 Pyobject_head4py_ssize_t Ma_fill; /*#Active + # Dummy * /5py_ssize_t ma_used; /*#Active * /6 7/* The table contains Ma_mask + 1 slots, andThat's a power of 2.8* We Store The mask instead of the size because the mask is More9*frequently needed.Ten*/ One py_ssize_t Ma_mask; A  -/* ma_table points to ma_smalltable forSmall tables,Else to -* Additional malloc'Ed memory.  Ma_table is never null! This rule the* Saves repeated runtime null-testsinchThe Workhorse GetItem and -*SetItem calls. -*/ -Pydictentry *ma_table; +Pydictentry * (*ma_lookup) (Pydictobject *mp, Pyobject *key, long hash); - pydictentry ma_smalltable[pydict_minsize]; +};

You can see that the dict uses a hash data structure!

Python's DICT data structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.