Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

18.1. Inside the Dictionary

Dictionaries are represented by a C structure, PyDictObject, defined in Include/dictobject.h. Here's a schematic of the structure representing a small dictionary mapping "aa", "bb", "cc", …, "mm" to the integers 1 to 13:

	int ma_fill         13
	int ma_used         13
	int ma_mask         31

	PyDictEntry ma_table[]:
	[0]: aa, 1                  hash(aa) == -1549758592, -1549758592 & 31 = 0
	[1]: ii, 9                  hash(ii) == -1500461680, -1500461680 & 31 = 16	
	[2]: null, null
	[3]: null, null 
	[4]: null, null
	[5]: jj, 10                 hash(jj) == 653184214, 653184214 & 31 = 22
	[6]: bb, 2                  hash(bb) == 603887302, 603887302 & 31 = 6
	[7]: null, null 
	[8]: cc, 3                  hash(cc) == -1537434360, -1537434360 & 31 = 8
	[9]: null, null
	[10]: dd, 4                 hash(dd) == 616211530, 616211530 & 31 = 10
	[11]: null, null
	[12]: null, null
	[13]: null, null
	[14]: null, null 
	[15]: null, null
	[16]: gg, 7                 hash(gg) == -1512785904, -1512785904 & 31 = 16
	[17]: ee, 5                 hash(ee) == -1525110136, -1525110136 & 31 = 8
	[18]: hh, 8                 hash(hh) == 640859986, 640859986 & 31 = 18
	[19]: null, null
	[20]: null, null
	[21]: kk, 11                hash(kk) == -1488137240, -1488137240 & 31 = 8
	[22]: ff, 6                 hash(ff) == 628535766, 628535766 & 31 = 22
	[23]: null, null
	[24]: null, null
	[25]: null, null
	[26]: null, null
	[27]: null, null
	[28]: null, null
	[29]: ll, 12                hash(ll) == 665508394, 665508394 & 31 = 10
	[30]: mm, 13                hash(mm) == -1475813016, -1475813016 & 31 = 8 
	[31]: null, null

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial