当前位置: 首页>>代码示例>>Python>>正文


Python objectmodel.compute_identity_hash函数代码示例

本文整理汇总了Python中pypy.rlib.objectmodel.compute_identity_hash函数的典型用法代码示例。如果您正苦于以下问题:Python compute_identity_hash函数的具体用法?Python compute_identity_hash怎么用?Python compute_identity_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compute_identity_hash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_hash_preservation

    def test_hash_preservation(self):
        from pypy.rlib.objectmodel import current_object_addr_as_int
        from pypy.rlib.objectmodel import compute_identity_hash
        class C:
            pass
        class D(C):
            pass
        c = C()
        d = D()
        h_c = compute_identity_hash(c)
        h_d = compute_identity_hash(d)
        #
        def f():
            d2 = D()
            return (compute_identity_hash(d2),
                    current_object_addr_as_int(d2),
                    compute_identity_hash(c),
                    compute_identity_hash(d))

        res = self.interpret(f, [])
        # xxx the following test is too precise, checking the exact
        # implementation.  On Python 2.7 it doesn't work anyway, because
        # object.__hash__(x) is different from id(x).  The test is disabled
        # for now, and nobody should rely on compute_identity_hash() returning
        # a value that is (or was) the current_object_addr_as_int().
        # --- disabled: assert res.item0 == res.item1
        # the following property is essential on top of the lltypesystem
        # otherwise prebuilt dictionaries are broken.  It's wrong on
        # top of the ootypesystem though.
        if isinstance(self, LLRtypeMixin):
            assert res.item2 == h_c
            assert res.item3 == h_d
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:32,代码来源:test_rclass.py

示例2: test_hash_preservation

    def test_hash_preservation(self):
        from pypy.rlib.objectmodel import current_object_addr_as_int
        from pypy.rlib.objectmodel import compute_identity_hash

        class C:
            pass

        class D(C):
            pass

        c = C()
        d = D()
        h_c = compute_identity_hash(c)
        h_d = compute_identity_hash(d)
        #
        def f():
            d2 = D()
            return (
                compute_identity_hash(d2),
                current_object_addr_as_int(d2),
                compute_identity_hash(c),
                compute_identity_hash(d),
            )

        res = self.interpret(f, [])
        # xxx this is too precise, checking the exact implementation
        assert res.item0 == res.item1
        # the following property is essential on top of the lltypesystem
        # otherwise prebuilt dictionaries are broken.  It's wrong on
        # top of the ootypesystem though.
        if type(self) is TestLLtype:
            assert res.item2 == h_c
            assert res.item3 == h_d
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:test_rclass.py

示例3: f

 def f():
     d2 = D()
     return (
         compute_identity_hash(d2),
         current_object_addr_as_int(d2),
         compute_identity_hash(c),
         compute_identity_hash(d),
     )
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_rclass.py

示例4: fn

 def fn():
     objects = []
     hashes = []
     for i in range(200):
         rgc.collect(0)     # nursery-only collection, if possible
         obj = A()
         objects.append(obj)
         hashes.append(compute_identity_hash(obj))
     unique = {}
     for i in range(len(objects)):
         assert compute_identity_hash(objects[i]) == hashes[i]
         unique[hashes[i]] = None
     return len(unique)
开发者ID:pombredanne,项目名称:pypy,代码行数:13,代码来源:test_newgc.py

示例5: f

 def f():
     if compute_hash(c) != compute_identity_hash(c): return 12
     if compute_hash(d) != h_d: return 13
     if compute_hash(("Hi", None, (7.5, 2, d))) != h_t: return 14
     c2 = C()
     h_c2 = compute_hash(c2)
     if compute_hash(c2) != h_c2: return 15
     if compute_identity_hash(s) == h_s: return 16   # unlikely
     i = 0
     while i < 6:
         rgc.collect()
         if compute_hash(c2) != h_c2: return i
         i += 1
     return 42
开发者ID:pombredanne,项目名称:pypy,代码行数:14,代码来源:test_newgc.py

示例6: define_hash_preservation

 def define_hash_preservation(cls):
     from pypy.rlib.objectmodel import compute_hash
     from pypy.rlib.objectmodel import compute_identity_hash
     from pypy.rlib.objectmodel import current_object_addr_as_int
     class C:
         pass
     class D(C):
         pass
     c = C()
     d = D()
     h_d = compute_hash(d)     # force to be cached on 'd', but not on 'c'
     h_t = compute_hash(("Hi", None, (7.5, 2, d)))
     S = lltype.GcStruct('S', ('x', lltype.Signed),
                              ('a', lltype.Array(lltype.Signed)))
     s = lltype.malloc(S, 15, zero=True)
     h_s = compute_identity_hash(s)   # varsized: hash not saved/restored
     #
     def f():
         if compute_hash(c) != compute_identity_hash(c): return 12
         if compute_hash(d) != h_d: return 13
         if compute_hash(("Hi", None, (7.5, 2, d))) != h_t: return 14
         c2 = C()
         h_c2 = compute_hash(c2)
         if compute_hash(c2) != h_c2: return 15
         if compute_identity_hash(s) == h_s: return 16   # unlikely
         i = 0
         while i < 6:
             rgc.collect()
             if compute_hash(c2) != h_c2: return i
             i += 1
         return 42
     return f
开发者ID:pombredanne,项目名称:pypy,代码行数:32,代码来源:test_newgc.py

示例7: f1

 def f1():
     d2 = D()
     # xxx we assume that current_object_addr_as_int is defined as
     # simply returning the identity hash
     current_identityhash = current_object_addr_as_int(d2)
     instance_hash = compute_identity_hash(d2)
     return current_identityhash == instance_hash
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_ooclean.py

示例8: ll_set_null

def ll_set_null(d, llkey):
    hash = compute_identity_hash(llkey)
    i = rdict.ll_dict_lookup(d, llkey, hash) & rdict.MASK
    if d.entries.everused(i):
        # If the entry was ever used, clean up its key and value.
        # We don't store a NULL value, but a dead weakref, because
        # the entry must still be marked as everused().
        d.entries[i].key = llmemory.dead_wref
        d.entries[i].value = NULLVALUE
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:_rweakkeydict.py

示例9: args_hash

def args_hash(args):
    res = 0x345678
    for arg in args:
        if isinstance(arg, history.Const):
            y = arg._get_hash_()
        else:
            y = compute_identity_hash(arg)
        res = intmask((1000003 * res) ^ y)
    return res
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:optimizeutil.py

示例10: build

 def build(xr, n):
     "Build the identity hashes of all n objects of the chain."
     i = 0
     while i < n:
         xr.hash = compute_identity_hash(xr)
         # ^^^ likely to trigger a collection
         xr = xr.prev
         i += 1
     assert xr is None
开发者ID:pombredanne,项目名称:pypy,代码行数:9,代码来源:test_newgc.py

示例11: ll_get

def ll_get(d, llkey):
    hash = compute_identity_hash(llkey)
    i = rdict.ll_dict_lookup(d, llkey, hash) & rdict.MASK
    #llop.debug_print(lltype.Void, i, 'get', hex(hash),
    #                 ll_debugrepr(d.entries[i].key),
    #                 ll_debugrepr(d.entries[i].value))
    # NB. ll_valid() above was just called at least on entry i, so if
    # it is an invalid entry with a dead weakref, the value was reset
    # to NULLVALUE.
    return d.entries[i].value
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:_rweakkeydict.py

示例12: check

 def check(xr, n, step):
     "Check that the identity hashes are still correct."
     i = 0
     while i < n:
         if xr.hash != compute_identity_hash(xr):
             os.write(2, "wrong hash! i=%d, n=%d, step=%d\n" % (i, n,
                                                                step))
             raise ValueError
         xr = xr.prev
         i += 1
     assert xr is None
开发者ID:pombredanne,项目名称:pypy,代码行数:11,代码来源:test_newgc.py

示例13: args_hash

def args_hash(args):
    make_sure_not_resized(args)
    res = 0x345678
    for arg in args:
        if arg is None:
            y = 17
        elif isinstance(arg, history.Const):
            y = arg._get_hash_()
        else:
            y = compute_identity_hash(arg)
        res = intmask((1000003 * res) ^ y)
    return res
开发者ID:gorakhargosh,项目名称:pypy,代码行数:12,代码来源:util.py

示例14: descr_hash

 def descr_hash(self, space):
     w_func = self.getattr(space, "__hash__", False)
     if w_func is None:
         w_eq = self.getattr(space, "__eq__", False)
         w_cmp = self.getattr(space, "__cmp__", False)
         if w_eq is not None or w_cmp is not None:
             raise OperationError(space.w_TypeError, space.wrap("unhashable instance"))
         else:
             return space.wrap(compute_identity_hash(self))
     w_ret = space.call_function(w_func)
     if not space.is_true(space.isinstance(w_ret, space.w_int)) and not space.is_true(
         space.isinstance(w_ret, space.w_long)
     ):
         raise OperationError(space.w_TypeError, space.wrap("__hash__ must return int or long"))
     return w_ret
开发者ID:pombredanne,项目名称:pypy,代码行数:15,代码来源:interp_classobj.py

示例15: ll_set_nonnull

def ll_set_nonnull(d, llkey, llvalue):
    hash = compute_identity_hash(llkey)
    keyref = weakref_create(llkey)    # GC effects here, before the rest
    i = rdict.ll_dict_lookup(d, llkey, hash) & rdict.MASK
    everused = d.entries.everused(i)
    d.entries[i].key = keyref
    d.entries[i].value = llvalue
    d.entries[i].f_hash = hash
    #llop.debug_print(lltype.Void, i, 'stored', hex(hash),
    #                 ll_debugrepr(llkey),
    #                 ll_debugrepr(llvalue))
    if not everused:
        d.resize_counter -= 3
        if d.resize_counter <= 0:
            #llop.debug_print(lltype.Void, 'RESIZE')
            ll_weakdict_resize(d)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:16,代码来源:_rweakkeydict.py


注:本文中的pypy.rlib.objectmodel.compute_identity_hash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。