Python的dict資料結構

來源:互聯網
上載者:User

標籤:

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() abuses4      * 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 to14      * additional malloc‘ed memory.  ma_table is never NULL!  This rule15      * saves repeated runtime null-tests in the workhorse getitem and16      * 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資料結構!

Python的dict資料結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.