Exemplo n.º 1
0
 def from_dict(dico, key_conversion=NodeConversion(), value_conversion=NodeConversion(), freeit=False):
     """
     Creates an assoc from a pythonic dict
     
     :param dico: python dictionary
     :param key_conversion: the conversion for the key (object <--> pointer)
     :param value_conversion: the conversion of the value  (object <--> pointer)
     :param freeit: a flag indicating whether or not this object should be freed
                 upon garbage collection
     :return: an assoc with the same contents as the given dico
     """
     me = Assoc(_utils.new_assoc_with_size(len(dico)), key_conversion, value_conversion, freeit=freeit)
     for k,v in dico.items():
         me[k] = v
     return me
Exemplo n.º 2
0
 def empty(key_conversion=NodeConversion(), value_conversion=NodeConversion(), initial_capa=0, freeit=False):
     """
     Creates an empty assoc
     
     :param key_conversion: the conversion for the key (object <--> pointer)
     :param value_conversion: the conversion of the value  (object <--> pointer)
     :param initial capa: the initial capacity of the associative array
     :param freeit: a flag indicating whether or not this object should be freed
                 upon garbage collection
     :return: a new empty Assoc
     """
     if initial_capa == 0:
         return Assoc(_utils.new_assoc(), key_conversion, value_conversion, freeit=freeit)
     else:
         return Assoc(_utils.new_assoc_with_size(initial_capa), key_conversion, value_conversion, freeit=freeit)