def rt_equiv(self, other): if UT.is_satisfies(RT.IPersistentVector, other): if UT.equiv(RT.count.invoke1(self), UT.count(other)) is false: return false for x in range(self._cnt): i = wrap_int(x) if RT.equiv(RT.nth.invoke1(self, i), UT.nth(self, i)) is false: return false return true else: if RT.is_satisfies.invoke1(RT.Sequential, other) is false: return false ms = RT.seq.invoke1(other) for x in range(self._cnt): if ms is nil or UT.equiv(UT.nth(x, wrap_int(x)), UT.first(ms)) is false: return false ms = UT.next(ms) if ms is not nil: return false return true
def rt_hash(self): if self._hash is None: n = r_uint32(0) hash = r_uint32(1) for x in range(self._cnt): hash = r_uint32(31) * hash + UT.hash(UT.nth(wrap_int(x)))._int_value n += 1 x = RT.next.invoke1(x) self._hash = wrap_int(int(mix_col_hash(hash, n))) return self._hash
def rt_hash(self): if self._hash is None: n = r_uint32(0) hash = r_uint32(1) for x in range(self._cnt): hash = r_uint32(31) * hash + UT.hash(UT.nth( wrap_int(x)))._int_value n += 1 x = RT.next.invoke1(x) self._hash = wrap_int(int(mix_col_hash(hash, n))) return self._hash
def count(a): if is_satisfies.invoke2(ICounted, a) is true: return _count.invoke1(a) import numbers i = 0 c = seq.invoke1(a) while is_satisfies.invoke2(ICounted, c) is false: i += 1 c = next.invoke1(c) return _add.invoke2(count.invoke1(c), numbers.wrap_int(i))
def rt_hash(self): if self._hash is None: n = r_uint32(0) hash = r_uint32(1) x = RT.seq.invoke1(self) while x is not nil: hash = r_uint32(31) * hash + UT.hash(UT.first(x))._int_value n += 1 x = RT.next.invoke1(x) self._hash = wrap_int(int(mix_col_hash(hash, n))) return self._hash
def match_number(s): m = int_pat.match(s) if m: if m.group(2) is not None: if m.group(8) is not None: return bigint_zero return int_zero sign = -1 if m.group(1) == '-' else 1 radix = 10 n = m.group(3) if n is not None: radix = 10 if n is None: n = m.group(4) if n is not None: radix = 16 if n is None: n = m.group(5) if n is not None: radix = 8 if n is None: n = m.group(7) if n is not None: radix = int(m.group(6)) if n is None: return None bn = rbigint.fromstr( n, radix) # throws rpython.rlib.rstring.InvalidBaseError bn.sign = sign if m.group(8) is not None: return wrap_bigint(bn) elif bn.bit_length() < LONG_BIT: return wrap_int(bn.toint()) else: return wrap_bigint(bn) else: assert False, "TODO: implement other number types" return None
def match_number(s): m = int_pat.match(s) if m: if m.group(2) is not None: if m.group(8) is not None: return bigint_zero return int_zero sign = -1 if m.group(1) == '-' else 1 radix = 10 n = m.group(3) if n is not None: radix = 10 if n is None: n = m.group(4) if n is not None: radix = 16 if n is None: n = m.group(5) if n is not None: radix = 8 if n is None: n = m.group(7) if n is not None: radix = int(m.group(6)) if n is None: return None bn = rbigint.fromstr(n, radix) # throws rpython.rlib.rstring.InvalidBaseError bn.sign = sign if m.group(8) is not None: return wrap_bigint(bn) elif bn.bit_length() < LONG_BIT: return wrap_int(bn.toint()) else: return wrap_bigint(bn) else: assert False, "TODO: implement other number types" return None
def rt_first(self): return RT.nth.invoke1(self._v, wrap_int(self._idx))
def rt_hash(self): return wrap_int(int(hash_int(r_uint32(hash(self._str_value)))))
def match_number(s): ## TODO: expand return wrap_int(int(s))
def count(a): assert isinstance(a, PersistentVector) return wrap_int(int(a._cnt))
def rt_hash(self): h = hash_combine(r_uint32(UT.hash(self._name)._int_value), r_uint32(UT.hash(self._ns)._int_value)) return wrap_int(int(h))
def rt_index(self): return wrap_int(self._idx)
def rt_count(self): return wrap_int(RT.count.invoke1(self._v)._int_value - 1)