#NEWLINE# def __init__( self , buf = None , length = 0 ) : #NEWLINE# #INDENT# 'Create a new SparseMap. The constructor accepts a buffer and\n        byte_length, a python dict containing { offset: array, ... }, or a\n        pointer to a C structure' #NEWLINE# if isinstance ( buf , dict ) : #NEWLINE# #INDENT# items = buf #NEWLINE# buf = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# items = None #NEWLINE# #UNINDENT# if isinstance ( buf , MapPtr ) : #NEWLINE# #INDENT# self . _ptr = buf #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( buf is not None ) : #NEWLINE# #INDENT# if IS_PYPY : #NEWLINE# #INDENT# buf = create_string_buffer ( str ( buf ) ) #NEWLINE# #UNINDENT# if isinstance ( buf , buffer ) : #NEWLINE# #INDENT# address = c_void_p ( ) #NEWLINE# buf_length = c_size_t ( ) #NEWLINE# pythonapi . PyObject_AsReadBuffer ( py_object ( buf ) , byref ( address ) , byref ( buf_length ) ) #NEWLINE# buf_length = buf_length . value #NEWLINE# buf = address #NEWLINE# #UNINDENT# buf = cast ( buf , Uint32Ptr ) #NEWLINE# #UNINDENT# self . _ptr = Gauged . map_import ( buf , length ) #NEWLINE# #UNINDENT# if ( self . _ptr is None ) : #NEWLINE# #INDENT# raise MemoryError #NEWLINE# #UNINDENT# SparseMap . ALLOCATIONS += 1 #NEWLINE# if ( items is not None ) : #NEWLINE# #INDENT# for position in sorted ( items . keys ( ) ) : #NEWLINE# #INDENT# self . append ( position , items [ position ] )