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


Python lru.LRU類代碼示例

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


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

示例1: test_lru

    def test_lru(self):
        l = LRU(1)
        l["a"] = 1
        l["a"]
        self.assertEqual(l.keys(), ["a"])
        l["b"] = 2
        self.assertEqual(l.keys(), ["b"])

        l = LRU(2)
        l["a"] = 1
        l["b"] = 2
        self.assertEqual(len(l), 2)
        l["a"]  # Testing the first one
        l["c"] = 3
        self.assertEqual(sorted(l.keys()), ["a", "c"])
        l["c"]
        self.assertEqual(sorted(l.keys()), ["a", "c"])

        l = LRU(3)
        l["a"] = 1
        l["b"] = 2
        l["c"] = 3
        self.assertEqual(len(l), 3)
        l["b"]  # Testing the middle one
        l["d"] = 4
        self.assertEqual(sorted(l.keys()), ["b", "c", "d"])
        l["d"]  # Testing the last one
        self.assertEqual(sorted(l.keys()), ["b", "c", "d"])
        l["e"] = 5
        self.assertEqual(sorted(l.keys()), ["b", "d", "e"])
開發者ID:pombredanne,項目名稱:lru-dict,代碼行數:30,代碼來源:test_lru.py

示例2: test_lru

    def test_lru(self):
        l = LRU(1)
        l['a'] = 1
        l['a']
        self.assertEqual(l.keys(), ['a'])
        l['b'] = 2
        self.assertEqual(l.keys(), ['b'])

        l = LRU(2)
        l['a'] = 1
        l['b'] = 2
        self.assertEqual(len(l), 2)
        l['a']                  # Testing the first one
        l['c'] = 3
        self.assertEqual(sorted(l.keys()), ['a', 'c'])
        l['c']
        self.assertEqual(sorted(l.keys()), ['a', 'c'])

        l = LRU(3)
        l['a'] = 1
        l['b'] = 2
        l['c'] = 3
        self.assertEqual(len(l), 3)
        l['b']                  # Testing the middle one
        l['d'] = 4
        self.assertEqual(sorted(l.keys()), ['b', 'c', 'd'])
        l['d']                  # Testing the last one
        self.assertEqual(sorted(l.keys()), ['b', 'c', 'd'])
        l['e'] = 5
        self.assertEqual(sorted(l.keys()), ['b', 'd', 'e'])
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:30,代碼來源:test_lru.py

示例3: __init__

    def __init__(self):
        '''
        '''
        self._views = LRU(50)
        # tile cache - enough for 1 MFOV for 10 parallel users
        self._tiles = LRU(61 * 10)

        self._client_tiles = {}
開發者ID:Rhoana,項目名稱:mb,代碼行數:8,代碼來源:manager.py

示例4: test_access_within_size

 def test_access_within_size(self):
     for size in SIZES:
         l = LRU(size)
         for i in xrange(size):
             l[i] = str(i)
         for i in xrange(size):
             self.assertEquals(l[i], str(i))
             self.assertEquals(l.get(i,None), str(i))
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:8,代碼來源:test_lru.py

示例5: test_has_key

 def test_has_key(self):
     for size in SIZES:
         l = LRU(size)
         for i in xrange(2*size):
             l[i] = str(i)
             self.assertTrue(l.has_key(i))
         for i in xrange(size, 2*size):
             self.assertTrue(l.has_key(i))
         for i in xrange(size):
             self.assertFalse(l.has_key(i))
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:10,代碼來源:test_lru.py

示例6: test_get_and_del

 def test_get_and_del(self):
     l = LRU(2)
     l[1] = '1'
     self.assertEqual('1', l.get(1))
     self.assertEqual('1', l.get(2, '1'))
     self.assertIsNone(l.get(2))
     self.assertEqual('1', l[1])
     self.assertRaises(KeyError, lambda: l['2'])
     with self.assertRaises(KeyError):
         del l['2']
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:10,代碼來源:test_lru.py

示例7: test_access

 def test_access(self):
     for size in SIZES:
         l = LRU(size)
         n = size * 2
         for i in xrange(n):
             l[i] = str(i)
         self._check_kvi(range(n-1,size-1,-1), l)
         for i in xrange(size, n):
             self.assertEquals(l[i], str(i))
             self.assertEquals(l.get(i,None), str(i))
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:10,代碼來源:test_lru.py

示例8: __init__

 def __init__(self, c_hash, c_user, c_words):
     self.topic_count =1
     # self.time = (self.first,self.last)
     self.l1 = LRU(c_hash)
     self.first =""
     self.last=""
     self.lats=[]
     self.longs=[]
     self.l2 = LRU(c_user)
     self.l3 = LRU(c_words)
     self.l4 = LRU(400)
開發者ID:nishucsd,項目名稱:thesis,代碼行數:11,代碼來源:clusters4.py

示例9: test_clear

 def test_clear(self):
     for size in SIZES:
         l = LRU(size)
         for i in range(size+5):
             l[i] = str(i)
         l.clear()
         for i in range(size):
             l[i] = str(i)
         for i in xrange(size):
             _ = l[random.randint(0, size-1)]
         l.clear()
         self.assertTrue(len(l) == 0)
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:12,代碼來源:test_lru.py

示例10: __init__

 def __init__(self, mtp, pstorage=None):
    global PATH_CACHE_SIZE
    MTPRefresh.__init__(self)
    self.mtp = mtp
    self.libmtp = mtp.libmtp
    self.open_device = mtp.open_device
    self.directories = None
    self.contents = LRU(PATH_CACHE_SIZE)
    if pstorage is None:
       MTPEntry.__init__(self, -3, '/')
       self.storage = None
       self.directories = []
       for dirname in self.mtp.get_storage_descriptions():
          #def __init__(self, path, id=-2, storageid=-2, folderid=-2, mtp=None, timestamp=0, is_refresh=True):
          self.directories.append(MTPFolder(path=dirname, id= -3, storageid= -3, folderid= -2, is_refresh=False)) 
       self.root = None
       self.contents[utf8(os.sep)] = self
    else:         
       self.storage = pstorage
       storage = pstorage.contents
       self.type = storage.StorageType
       self.freespace = storage.FreeSpaceInBytes
       self.capacity = storage.MaxCapacity
       path = os.sep + storage.StorageDescription
       MTPEntry.__init__(self, storage.id, path, storageid=None, folderid=0)
       self.root = MTPFolder(path=path, id=0, storageid=storage.id, folderid=0, mtp=self.mtp)
       self.contents[utf8(path)] = self.root
開發者ID:donaldmunro,項目名稱:pymtpfs,代碼行數:27,代碼來源:mtp.py

示例11: __init__

class Drawings:

    def __init__(self, max_active):
        self.drawings = LRU(max_active)
    
    def get_drawing(self, room):
        for (k, v) in self.drawings.items():
            logger.debug('{}: {} (len {})'.format(id(self), k , len(v)))
        try:
            d = self.drawings[room]
        except KeyError:
            d = self.drawings[room] = [ ]
        return d
開發者ID:recunius,項目名稱:iodraw,代碼行數:13,代碼來源:drawings.py

示例12: __init__

    def __init__(self, index=None, polygons=None, polygons_db=None, save_dir=None,
                 index_filename=None,
                 polygons_db_path=None,
                 include_only_properties=None):
        if save_dir:
            self.save_dir = save_dir
        else:
            self.save_dir = None

        if not index_filename:
            index_filename = self.INDEX_FILENAME

        self.index_path = os.path.join(save_dir or '.', index_filename)

        if not index:
            self.create_index(overwrite=True)
        else:
            self.index = index

        if include_only_properties and hasattr(include_only_properties, '__contains__'):
            self.include_only_properties = include_only_properties

        if not polygons and not self.persistent_polygons:
            self.polygons = {}
        elif polygons and not self.persistent_polygons:
            self.polygons = polygons
        elif self.persistent_polygons and self.cache_size > 0:
            self.polygons = LRU(self.cache_size)
            if polygons:
                for key, value in six.iteritems(polygons):
                    self.polygons[key] = value

            self.cache_hits = 0
            self.cache_misses = 0

            self.get_polygon = self.get_polygon_cached

        if not polygons_db_path:
            polygons_db_path = os.path.join(save_dir or '.', self.POLYGONS_DB_DIR)

        if not polygons_db:
            self.polygons_db = LevelDB(polygons_db_path)
        else:
            self.polygons_db = polygons_db

        self.setup()

        self.i = 0
開發者ID:BERENZ,項目名稱:libpostal,代碼行數:48,代碼來源:index.py

示例13: __init__

 def __init__(self, mtp, mountpoint, is_debug=False, logger=None):
    global VERBOSE
    self.mtp = mtp
    self.is_debug = is_debug
    self.tempdir = tempfile.mkdtemp(prefix='pymtpfs')
    if not bool(self.tempdir) or not os.path.exists(self.tempdir):
       self.tempdir = tempfile.gettempdir()
    self.read_timeout = 2
    self.write_timeout = 2      
    self.openfile_t = namedtuple('openfile', 'handle, path, mtp_path, readonly')
    self.openfiles = {}
    self.log = logger
    self.created = LRU(1000) 
    if VERBOSE:         
       print("Mounted %s on %s" % (self.mtp, ))
    self.log.info("Mounted %s on %s" % (self.mtp, mountpoint))
開發者ID:donaldmunro,項目名稱:pymtpfs,代碼行數:16,代碼來源:pymtpfs.py

示例14: test_capacity_set

 def test_capacity_set(self):
     for size in SIZES:
         l = LRU(size)
         for i in range(size+5):
             l[i] = str(i)
         l.set_size(size+10)
         self.assertTrue(size+10 == l.get_size())
         self.assertTrue(len(l) == size)
         for i in range(size+20):
             l[i] = str(i)
         self.assertTrue(len(l) == size+10)
         l.set_size(size+10-1)
         self.assertTrue(len(l) == size+10-1)
開發者ID:snorfalorpagus,項目名稱:lru-dict,代碼行數:13,代碼來源:test_lru.py

示例15: __init__

class topic:
    def __init__(self, c_hash, c_user, c_words):
        self.topic_count =1
        self.l1 = LRU(c_hash)
        self.l2 = LRU(c_user)
        self.l3 = LRU(c_words)

    def set_hashLRU(self,l):
        self.set(self.l1, l)

    def set_userLRU(self,l):
        self.set(self.l2, l)

    def set_wordLRU(self,l):
        self.set(self.l3, l)

    def set(self, lru, l):
        for k in l:
            v = lru.get(k,0)
            lru[k]=v+1

    def set_cluster(self, hashtags, users, words):
        for k in hashtags:
            v = self.l1.get(k,0)
            self.l1[k]=v+1
        for k in users:
            v = self.l2.get(k,0)
            self.l2[k]=v+1
        for k in words:
            v = self.l3.get(k,0)
            self.l3[k]=v+1
        self.topic_count+=1

    def get_similarity(self,hashtags,users,words):
        h_sum = 0
        u_sum = 0
        w_sum = 0

        for h in hashtags:
            h_sum+= self.l1.get(h,0)
        for u in users:
            u_sum+= self.l2.get(u,0)
        for w in words:
            w_sum+= self.l3.get(w,0)

        similarity = 0.5*h_sum + 0.2*u_sum + 0.3*w_sum
        return similarity
開發者ID:nishucsd,項目名稱:thesis,代碼行數:47,代碼來源:clusters.py


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