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


Python LinkedList.back方法代码示例

本文整理汇总了Python中linkedlist.LinkedList.back方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.back方法的具体用法?Python LinkedList.back怎么用?Python LinkedList.back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linkedlist.LinkedList的用法示例。


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

示例1: test_empty_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
 def test_empty_list(self):
     llist = LinkedList()
     self.assertEqual(len(llist), 0)
     self.assertIsNone(llist.next())
     self.assertIsNone(llist.prev())
     self.assertEqual(llist.prev(), llist.back())
     self.assertEqual(llist.next(), llist.front())
     self.assertEqual(llist.back(), llist.front())
     self.assertFalse(bool(llist))
开发者ID:sthe0,项目名称:task3,代码行数:11,代码来源:test.py

示例2: test_non_empty_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
 def test_non_empty_list(self):
     llist = LinkedList()
     llist.push_back(1)
     self.assertIsNotNone(llist.next())
     self.assertIsNotNone(llist.prev())
     self.assertEqual(llist.prev(), llist.back())
     self.assertEqual(llist.next(), llist.front())
     self.assertEqual(llist.back(), llist.front())
     self.assertTrue(bool(llist))
开发者ID:sthe0,项目名称:task3,代码行数:11,代码来源:test.py

示例3: test_clear

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
 def test_clear(self):
     llist = LinkedList()
     for i in xrange(10):
         llist.push_back(i)
     llist.clear()
     self.assertFalse(bool(llist))
     self.assertIsNone(llist.back())
开发者ID:sthe0,项目名称:task3,代码行数:9,代码来源:test.py

示例4: RuleList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
class RuleList(object):
    def __init__(self, max_size = 10):
        self.__list = LinkedList()
        self.__cmp = BoolCmp(1e-9)
        self.__max_size = max_size
        self.__rule_set = set()

    def insert(self, informativity, rule):
        if rule in self.__rule_set:
            return
        self.__rule_set.add(rule)

        if not self.__list or self.__cmp(self.__list.back().value[0], informativity) > 0:
            self.__list.push_back([informativity, rule])
        else:
            for node in self.__list:
                if self.__cmp(node.value[0], informativity) > 0:
                    continue
                if self.__cmp(node.value[0], informativity) == 0:
                    node.value.append(rule)
                if self.__cmp(node.value[0], informativity) < 0:
                    self.__list.insert_before(node, [informativity, rule])
                break
        if len(self.__rule_set) - (len(self.__list.back().value) - 1) >= self.__max_size:
            for item in self.__list.back().value[1:]:
                self.__rule_set.remove(item)
            self.__list.remove(self.__list.back())

    def clear(self):
        self.__list = LinkedList()
        self.__rule_set = set()

    def __iter__(self):
        for node in self.__list:
            for item in node.value[1:]:
                yield node.value[0], item

    def __len__(self):
        return len(self.__rule_set)

    def __contains__(self, rule):
        return rule in self.__rule_set
开发者ID:sthe0,项目名称:task3,代码行数:44,代码来源:rulebuilder.py

示例5: test_remove

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
    def test_remove(self):
        llist = LinkedList()
        for i in xrange(10):
            llist.push_back(i)
        for item in llist:
            if item.value % 2 == 0:
                llist.remove(item)
        self.assertEqual([node.value for node in llist], range(1,10,2))

        for i in xrange(5):
            llist.remove(llist.back())
        self.assertFalse(bool(llist))
开发者ID:sthe0,项目名称:task3,代码行数:14,代码来源:test.py

示例6: LRUCache

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import back [as 别名]
class LRUCache(object):
    def __init__(self, capacity):
        self.init(capacity)

    def init(self, capacity):
        self.capacity = capacity
        self.table = {}
        self.data = LinkedList()
        self.hitcnt = self.misscnt = self.expirecnt = 0
        self.lock = threading.Lock()

    def stats(self):
        per = 1.0 * self.hitcnt / max(1, self.misscnt + self.expirecnt + self.misscnt);
        return "size = %d, hitcnt = %d, misscnt = %d, expirecnt = %d, hit per=%.4lf\n" % (
                len(self.table), self.hitcnt, self.misscnt, self.expirecnt, per)

    def delete(self, key):
        with self.lock:
            if key in self.table:
                node = self.table[key]
                self.data.remove(node)
                del self.table[key]
                return True

    def get(self, key):
        """
        get the cache value with specifiy key
        return None either key is not found or value is expired
        """
        with self.lock:
            if key in self.table:
                node = self.table[key]
                if node.elem.expire < time.time():
                    #expire
                    self.expirecnt += 1
                    self.data.remove(node)
                    del self.table[key]
                else:
                    self.hitcnt += 1
                    self.data.move_to_front(node)
                    return node.elem.value
            else:
                self.misscnt += 1

    def setex(self, key, seconds, value):
        with self.lock:
            expire = int(time.time()) + seconds
            if key in self.table:
                #already exists
                node = self.table[key]
                node.elem = Entry(key, value, expire)
                self.data.move_to_front(node)
            else:
                self._add(key, expire, value)

    def _add(self, key, expire, value):
        node = self.data.push_front(Entry(key, value, expire))
        self.table[key] = node 
        if len(self.table) > self.capacity:
            node = self.data.back()
            self.data.remove(node)
            del self.table[node.elem.key]
开发者ID:Lin53,项目名称:playground,代码行数:64,代码来源:test_lru.py


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