當前位置: 首頁>>代碼示例>>Python>>正文


Python pyebset.BitSet類代碼示例

本文整理匯總了Python中pyebset.BitSet的典型用法代碼示例。如果您正苦於以下問題:Python BitSet類的具體用法?Python BitSet怎麽用?Python BitSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BitSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_set

 def test_set(self):
     b = BitSet()
     self.assertTrue(b.set(0))
     self.assertTrue(b.set(1))
     self.assertTrue(b.set(2))
     self.assertTrue(b.set(3))
     self.assertFalse(b.set(1))
開發者ID:UIKit0,項目名稱:hustle,代碼行數:7,代碼來源:pyebset_test.py

示例2: bit_eq

 def bit_eq(self, ix, key):
     _, idb, _, column = self.dbs[ix]
     rval = BitSet()
     zkey = self._vid_for_value(column, key)
     if zkey is not None:
         val = idb.get(self.txn, zkey)
         if val is not None:
             rval.loads(val)
     return rval
開發者ID:dinedal,項目名稱:hustle,代碼行數:9,代碼來源:marble.py

示例3: get_ix

 def get_ix(self, column_name, key):
     _, idb, _, _ = self.dbs[column_name]
     bitset = BitSet()
     try:
         data = idb.get(self.txn, key)
         bitset.loads(data)
     except:
         pass
     return bitset
開發者ID:dinedal,項目名稱:hustle,代碼行數:9,代碼來源:marble.py

示例4: _bit_op

 def _bit_op(self, val, op):
     rval = BitSet()
     it = op(self.txn, val)
     for _, v in it:
         if v is None:
             continue
         bitset = BitSet()
         bitset.loads(v)
         rval |= bitset
     return rval
開發者ID:dinedal,項目名稱:hustle,代碼行數:10,代碼來源:marble.py

示例5: test_logical_not

 def test_logical_not(self):
     b = BitSet()
     b.set(0)
     b.set(1)
     b.set(8)
     b.set(9)
     c = ~b
     # test the logical not doesn't generate any numbers that are greater
     # than 9 in this case
     self.assertEqual(list(c), [2, 3, 4, 5, 6, 7])
開發者ID:pooya,項目名稱:hustle,代碼行數:10,代碼來源:pyebset_test.py

示例6: test_marble_insert

 def test_marble_insert(self):
     #  test general infomation
     self.assertEqual(self.n_inserted, len(_ALBUMS))
     self.assertEqual(_NPARTITIONS, len(self.files))
     part_id = {}
     #  test that each sub db is fine
     for date, file in self.files.iteritems():
         env, txn, dbs, meta = self.marble._open(file)
         #  check meta db
         self.assertTrue(meta.contains(txn, "_vid_nodes"))
         self.assertTrue(meta.contains(txn, "_vid_kids"))
         self.assertTrue(meta.contains(txn, "_vid16_nodes"))
         self.assertTrue(meta.contains(txn, "_vid16_kids"))
         self.assertEqual(meta.get(txn, "name"), ujson.dumps("Collections"))
         self.assertEqual(meta.get(txn, "partition"), ujson.dumps("date"))
         self.assertEqual(meta.get(txn, "fields"), ujson.dumps(_FIELDS))
         self.assertEqual(meta.get(txn, "_pdata"), ujson.dumps(date))
         vid_nodes, _ = meta.get_raw(txn, '_vid_nodes')
         vid_kids, _ = meta.get_raw(txn, '_vid_kids')
         vid16_nodes, _ = meta.get_raw(txn, '_vid16_nodes', (None, 0))
         vid16_kids, _ = meta.get_raw(txn, '_vid16_kids', (None, 0))
         #  check subdb, subinddb
         part_id[date] = 1
         for name, (db, ind_db, _, column, _) in dbs.iteritems():
             if name == "_count":
                 continue
             bitmaps = {}
             part_id[date] = 1
             for album in self.albums:
                 if date == album[_PARTITIONS]:  # match the partition
                     value = album[name]
                     i = part_id[album[_PARTITIONS]]
                     part_id[album[_PARTITIONS]] += 1
                     if column.is_trie:
                         if column.rtrie_indicator == mdb.MDB_UINT_16:
                             val = rtrie.vid_for_value(vid16_nodes, vid16_kids, value)
                         else:
                             val = rtrie.vid_for_value(vid_nodes, vid_kids, value)
                     elif column.is_lz4:
                         val = clz4.compress(value)
                     else:
                         val = value
                     # self.assertEqual(db.get(txn, i), val)
                     if ind_db is not None:
                         #  row_id should be in bitmap too
                         if val in bitmaps:
                             bitmap = bitmaps[val]
                         else:
                             bitmap = BitSet()
                             bitmap.loads(ind_db.get(txn, val))
                             bitmaps[val] = bitmap
                         self.assertTrue(i in bitmap)
         txn.commit()
         env.close()
開發者ID:UIKit0,項目名稱:hustle,代碼行數:54,代碼來源:test_marble.py

示例7: test_generator

 def test_generator(self):
     b = BitSet()
     b.set(1)
     b.set(4)
     b.set(10)
     b.set(100000)
     b.set(12323131)
     self.assertEqual(list(b), [1, 4, 10, 100000, 12323131])
開發者ID:UIKit0,項目名稱:hustle,代碼行數:8,代碼來源:pyebset_test.py

示例8: mdb_fetch

def mdb_fetch(key, txn=None, ixdb=None):
    from pyebset import BitSet
    try:
        bitmaps = ixdb.get(txn, key)
    except:
        bitmaps = None

    if bitmaps is not None:
        bitset = BitSet()
        bitset.loads(bitmaps)
        return bitset
    return None
開發者ID:dinedal,項目名稱:hustle,代碼行數:12,代碼來源:marble.py

示例9: test_logical_not_1

 def test_logical_not_1(self):
     b = BitSet()
     b.set(0)
     b.set(1)
     b.set(7)
     b.set(8)
     c = ~b
     # test the logical not doesn't generate any numbers that are greater
     # than 9 in this case
     self.assertEqual(list(c), [2, 3, 4, 5, 6])
     d = ~c
     self.assertListEqual(list(d), [0, 1, 7, 8])
開發者ID:UIKit0,項目名稱:hustle,代碼行數:12,代碼來源:pyebset_test.py

示例10: test_contains

 def test_contains(self):
     b = BitSet()
     b.set(1)
     b.set(4)
     b.set(10)
     b.set(100000)
     b.set(12323131)
     for i in [1, 4, 10, 100000, 12323131]:
         self.assertTrue(i in b)
開發者ID:dinedal,項目名稱:hustle,代碼行數:9,代碼來源:pyebset_test.py

示例11: Tablet

class Tablet(object):
    def __init__(self, l=()):
        self.l = BitSet()
        for i in l:
            self.l.set(i)

    def iter_all(self):
        return iter(self.l)

    def bit_eq(self, col, other):
        b = BitSet()
        for i in self.l:
            if i == other:
                b.set(i)
        return b

    def bit_ne(self, col, other):
        b = BitSet()
        for i in self.l:
            if i != other:
                b.set(i)
        return b

    def bit_lt(self, col, other):
        b = BitSet()
        for i in self.l:
            if i < other:
                b.set(i)
        return b

    def bit_gt(self, col, other):
        b = BitSet()
        for i in self.l:
            if i > other:
                b.set(i)
        return b

    def bit_ge(self, col, other):
        b = BitSet()
        for i in self.l:
            if i >= other:
                b.set(i)
        return b

    def bit_le(self, col, other):
        b = BitSet()
        for i in self.l:
            if i <= other:
                b.set(i)
        return b
開發者ID:pooya,項目名稱:hustle,代碼行數:50,代碼來源:test_expression.py

示例12: test_eq_ne

 def test_eq_ne(self):
     b = BitSet()
     b.set(1)
     b.set(2)
     bb = BitSet()
     bb.set(1)
     bb.set(2)
     cc = BitSet()
     cc.set(2)
     cc.set(3)
     self.assertTrue(b == bb)
     self.assertTrue(bb != cc)
開發者ID:UIKit0,項目名稱:hustle,代碼行數:12,代碼來源:pyebset_test.py

示例13: bit_eq_ex

 def bit_eq_ex(self, ix, keys):
     from collections import Iterable
     _, idb, _, column = self.dbs[ix]
     rval = BitSet()
     for key in keys:
         if isinstance(key, Iterable) and not isinstance(key, (basestring, unicode)):
             # in case the key is a composite object, just grab the first one
             key = key[0]
         zkey = self._vid_for_value(column, key)
         if zkey is not None:
             val = idb.get(self.txn, zkey)
             if val is not None:
                 bitset = BitSet()
                 bitset.loads(val)
                 rval |= bitset
     return rval
開發者ID:dinedal,項目名稱:hustle,代碼行數:16,代碼來源:marble.py

示例14: test_dumps_loads

 def test_dumps_loads(self):
     b = BitSet()
     self.assertTrue(b.set(0))
     self.assertTrue(b.set(1))
     self.assertTrue(b.set(4))
     self.assertTrue(b.set(8))
     self.assertTrue(b.set(16))
     s = BitSet()
     s.loads(b.dumps())
     self.assertEqual(b, s)
開發者ID:UIKit0,項目名稱:hustle,代碼行數:10,代碼來源:pyebset_test.py

示例15: bit_ne

 def bit_ne(self, ix, key):
     _, idb, _, column = self.dbs[ix]
     rval = BitSet()
     key = self._vid_for_value(column, key)
     if key is not None:
         val = idb.get(self.txn, key)
         if val is not None:
             rval.loads(val)
             rval |= ZERO_BS
             rval.set(self.number_rows)
             rval.lnot_inplace()
     return rval
開發者ID:dinedal,項目名稱:hustle,代碼行數:12,代碼來源:marble.py


注:本文中的pyebset.BitSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。