Parcourir la source

RD* operations only rely on the cache

Yentl Van Tendeloo il y a 8 ans
Parent
commit
d90adc1e88
1 fichiers modifiés avec 16 ajouts et 73 suppressions
  1. 16 73
      state/modelverse_state/main.py

+ 16 - 73
state/modelverse_state/main.py

@@ -223,8 +223,7 @@ class ModelverseState(object):
             first = self.cache[node][value]
             # Got hit, so validate
             if (self.edges[first][0] == node) and \
-                (len(self.outgoing[first]) == 1) and \
-                (self.values[self.edges[list(self.outgoing[first])[0]][1]] == value):
+                (value in [self.values[self.edges[i][1]] for i in self.outgoing[first]]):
                 return (self.edges[first][1], status.SUCCESS)
             # Hit but invalid now
             del self.cache[node][value]
@@ -232,22 +231,6 @@ class ModelverseState(object):
             # Didn't exist
             pass
 
-        # Get all outgoing links
-        if node in self.outgoing:
-            for e1 in self.outgoing[node]:
-                # For each link, we read the links that might link to a data value
-                if e1 in self.outgoing:
-                    for e2 in self.outgoing[e1]:
-                        # Now read out the target of the link
-                        target = self.edges[e2][1]
-                        # And access its value
-                        if target in self.values and self.values[target] == value:
-                            # Found a match
-                            # Now get the target of the original link
-                            self.cache.setdefault(node, {})[value] = e1
-                            print("Cache did not find, but still entry: %s at %s" % (value, node))
-                            return (self.edges[e1][1], status.SUCCESS)
-
         if node not in self.nodes and node not in self.edges:
             return (None, status.FAIL_RDICT_UNKNOWN)
         elif not self.is_valid_datavalue(value):
@@ -271,8 +254,7 @@ class ModelverseState(object):
             first = self.cache[node][value]
             # Got hit, so validate
             if (self.edges[first][0] == node) and \
-                (len(self.outgoing[first]) == 1) and \
-                (self.values[self.edges[list(self.outgoing[first])[0]][1]] == value):
+                (value in [self.values[self.edges[i][1]] for i in self.outgoing[first]]):
                 return (first, status.SUCCESS)
             # Hit but invalid now
             del self.cache[node][value]
@@ -280,27 +262,7 @@ class ModelverseState(object):
             # Didn't exist
             pass
 
-        # Get all outgoing links
-        found = None
-        if node in self.outgoing:
-            for e1 in self.outgoing[node]:
-                # For each link, we read the links that might link to a data value
-                if e1 in self.outgoing:
-                    for e2 in self.outgoing[e1]:
-                        # Now read out the target of the link
-                        target = self.edges[e2][1]
-                        # And access its value
-                        if target in self.values and self.values[target] == value:
-                            # Found a match
-                            # Now get the target of the original link
-                            if found is not None:
-                                print("Duplicate key on value: %s : %s (%s <-> %s)!" % (self.values[target], type(v), found, e1))
-                                return (None, status.FAIL_RDICTE_AMBIGUOUS)
-                            found = e1
-                            self.cache.setdefault(node, {})[value] = e1
-        if found is not None:
-            return (found, status.SUCCESS)
-        elif node not in self.nodes and node not in self.edges:
+        if node not in self.nodes and node not in self.edges:
             return (None, status.FAIL_RDICTE_UNKNOWN)
         elif not self.is_valid_datavalue(value):
             return (None, status.FAIL_RDICTE_OOB)
@@ -308,19 +270,6 @@ class ModelverseState(object):
             return (None, status.FAIL_RDICTE_NOT_FOUND)
 
     def read_dict_node(self, node, value_node):
-        try:
-            first = self.cache_node[node][value_node]
-            # Got hit, so validate
-            if (self.edges[first][0] == node) and \
-                (len(self.outgoing[first]) == 1) and \
-                (self.edges[list(self.outgoing[first])[0]][1] == value_node):
-                return (self.edges[first][1], status.SUCCESS)
-            # Hit but invalid now
-            del self.cache_node[node][value_node]
-        except KeyError:
-            # Didn't exist
-            pass
-
         e, s = self.read_dict_node_edge(node, value_node)
 
         if s != status.SUCCESS:
@@ -333,25 +282,19 @@ class ModelverseState(object):
         return (self.edges[e][1], status.SUCCESS)
 
     def read_dict_node_edge(self, node, value_node):
-        # Get all outgoing links
-        found = None
-        if node in self.outgoing:
-            for e1 in self.outgoing[node]:
-                # For each link, we read the links that might link to a data value
-                if e1 in self.outgoing:
-                    for e2 in self.outgoing[e1]:
-                        # And access its value
-                        if self.edges[e2][1] == value_node:
-                            # Found a match
-                            # Now get the target of the original link
-                            if found is not None:
-                                print("Duplicate key on node: %s (%s <-> %s)!" % (value_node, found, e1))
-                                return (None, status.FAIL_RDICTNE_AMBIGUOUS)
-                            found = e1
-
-        if found is not None:
-            return (found, status.SUCCESS)
-        elif node not in self.nodes and node not in self.edges:
+        try:
+            first = self.cache_node[node][value_node]
+            # Got hit, so validate
+            if (self.edges[first][0] == node) and \
+                (value_node in [self.edges[i][1] for i in self.outgoing[first]]):
+                return (first, status.SUCCESS)
+            # Hit but invalid now
+            del self.cache_node[node][value_node]
+        except KeyError:
+            # Didn't exist
+            pass
+
+        if node not in self.nodes and node not in self.edges:
             return (None, status.FAIL_RDICTNE_UNKNOWN)
         else:
             return (None, status.FAIL_RDICTNE_NOT_FOUND)