Exemplo n.º 1
0
 def impl_integer(l, index, item):
     index = handle_index(l, index)
     castedindex = _cast(index, indexty)
     casteditem = _cast(item, itemty)
     status = _list_setitem(l, castedindex, casteditem)
     if status == ListStatus.LIST_OK:
         return
     else:
         raise AssertionError("internal list error during settitem")
Exemplo n.º 2
0
 def impl(d, key, value):
     castedkey = _cast(key, keyty)
     castedval = _cast(value, valty)
     status = _dict_insert(d, castedkey, hash(castedkey), castedval)
     if status == Status.OK:
         return
     elif status == Status.OK_REPLACED:
         # replaced
         # XXX handle refcount
         return
     elif status == Status.ERR_CMP_FAILED:
         raise ValueError('key comparison failed')
     else:
         raise RuntimeError('dict.__setitem__ failed unexpectedly')
Exemplo n.º 3
0
 def impl(l, item):
     casteditem = _cast(item, itemty)
     for i in l:
         if i == casteditem:
             return True
     else:
         return False
Exemplo n.º 4
0
 def impl(l, item):
     casteditem = _cast(item, itemty)
     total = 0
     for i in l:
         if i == casteditem:
             total += 1
     return total
Exemplo n.º 5
0
 def impl(l, index=-1):
     if len(l) == 0:
         raise IndexError("pop from empty list")
     cindex = _cast(handle_index(l, index), indexty)
     item = l[cindex]
     del l[cindex]
     return item
Exemplo n.º 6
0
 def impl(l, item, start=None, end=None):
     casteditem = _cast(item, itemty)
     for i in handle_slice(l, slice(start, end, 1)):
         if l[i] == casteditem:
             return i
     else:
         raise ValueError("item not in list")
Exemplo n.º 7
0
 def integer_non_none_impl(l, index):
     index = handle_index(l, index)
     castedindex = _cast(index, indexty)
     status, item = _list_getitem(l, castedindex)
     if status == ListStatus.LIST_OK:
         return _nonoptional(item)
     else:
         raise AssertionError("internal list error during getitem")
Exemplo n.º 8
0
 def impl(l, item):
     casteditem = _cast(item, itemty)
     for i, n in enumerate(l):
         if casteditem == n:
             l.pop(i)
             return
     else:
         raise ValueError("list.remove(x): x not in list")
Exemplo n.º 9
0
 def impl(l, item):
     casteditem = _cast(item, itemty)
     status = _list_append(l, casteditem)
     if status == ListStatus.LIST_OK:
         return
     elif status == ListStatus.LIST_ERR_NO_MEMORY:
         raise MemoryError('Unable to allocate memory to append item')
     else:
         raise RuntimeError('list.append failed unexpectedly')
Exemplo n.º 10
0
 def impl(d, key):
     castedkey = _cast(key, keyty)
     ix, val = _dict_lookup(d, castedkey, hash(castedkey))
     if ix == DKIX.EMPTY:
         raise KeyError()
     elif ix < DKIX.EMPTY:
         raise AssertionError("internal dict error during lookup")
     else:
         return _nonoptional(val)
Exemplo n.º 11
0
 def integer_impl(l, index):
     cindex = _cast(handle_index(l, index), INDEXTY)
     status = _list_delitem(l, cindex)
     if status == ListStatus.LIST_OK:
         return
     elif status == ListStatus.LIST_ERR_IMMUTABLE:
         raise ValueError("list is immutable")
     else:
         raise AssertionError("internal list error during delitem")
Exemplo n.º 12
0
 def impl(l, index=-1):
     if len(l) == 0:
         raise IndexError("pop from empty list")
     index = handle_index(l, index)
     castedindex = _cast(index, indexty)
     status, item = _list_pop(l, castedindex)
     if status == ListStatus.LIST_OK:
         return _nonoptional(item)
     else:
         raise AssertionError("internal list error during pop")
Exemplo n.º 13
0
 def impl(l, item):
     casteditem = _cast(item, itemty)
     status = _list_append(l, casteditem)
     if status == ListStatus.LIST_OK:
         return
     elif status == ListStatus.LIST_ERR_IMMUTABLE:
         raise ValueError("list is immutable")
     elif status == ListStatus.LIST_ERR_NO_MEMORY:
         raise MemoryError("Unable to allocate memory to append item")
     else:
         raise RuntimeError("list.append failed unexpectedly")
Exemplo n.º 14
0
 def impl_type_matched(da, db):
     if len(da) != len(db):
         return False
     for ka, va in da.items():
         # Cast key from LHS to the key-type of RHS
         kb = _cast(ka, otherkeyty)
         ix, vb = _dict_lookup(db, kb, hash(kb))
         if ix <= DKIX.EMPTY:
             # Quit early if the key is not found
             return False
         if va != vb:
             # Quit early if the values do not match
             return False
     return True
Exemplo n.º 15
0
 def impl(dct, key, default=None):
     castedkey = _cast(key, keyty)
     hashed = hash(castedkey)
     ix, val = _dict_lookup(dct, castedkey, hashed)
     if ix == DKIX.EMPTY:
         if should_raise:
             raise KeyError()
         else:
             return default
     elif ix < DKIX.EMPTY:
         raise AssertionError("internal dict error during lookup")
     else:
         status = _dict_delitem(dct, hashed, ix)
         if status != Status.OK:
             raise AssertionError("internal dict error during delitem")
         return val
Exemplo n.º 16
0
 def impl(d, k):
     k = _cast(k, keyty)
     ix, val = _dict_lookup(d, k, hash(k))
     return ix > DKIX.EMPTY
Exemplo n.º 17
0
 def impl(lst, index):
     index = fix_index(lst, index)
     castedindex = _cast(index, types.intp)
     _, item = _list_getitem(lst, castedindex)
     return _nonoptional(item)
Exemplo n.º 18
0
 def impl(dct, key, default=None):
     castedkey = _cast(key, keyty)
     ix, val = _dict_lookup(dct, key, hash(castedkey))
     if ix > DKIX.EMPTY:
         return val
     return default