Implemented SheerkaOntology

This commit is contained in:
2021-01-11 15:36:03 +01:00
parent e3c2adb533
commit e26c83a825
119 changed files with 6876 additions and 2002 deletions
+14 -2
View File
@@ -1,12 +1,16 @@
from core.global_symbols import NotFound
class FastCache:
"""
Simplest LRU cache
"""
def __init__(self, max_size=256):
def __init__(self, max_size=256, default=None):
self.max_size = max_size
self.cache = {}
self.lru = []
self.default = default
def put(self, key, value):
if len(self.cache) == self.max_size:
@@ -18,11 +22,19 @@ class FastCache:
self.cache[key] = value
self.lru.append(key)
def has(self, key):
return key in self.cache
def get(self, key):
try:
return self.cache[key]
except KeyError:
return None
if self.default:
value = self.default(key)
self.put(key, value)
return value
return NotFound
def evict_by_key(self, predicate):
to_remove = []