From c0c89e465a191d676c8a8f2f16a4ea2939046616 Mon Sep 17 00:00:00 2001 From: Bastian Koppelmann Date: Fri, 3 Jan 2020 11:49:51 +0100 Subject: [PATCH] vector: Implement hash cache for vector3d and vector this gives us a small runtime improvement in the router. For FreePDK45 word_size=8, num_words=256 Improved *** Maze routing supplies: 89.8 seconds ** Routing: 279.3 seconds Non-improved *** Maze routing supplies: 105.1 seconds ** Routing: 293.5 seconds Signed-off-by: Bastian Koppelmann --- compiler/base/vector.py | 3 ++- compiler/router/vector3d.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/base/vector.py b/compiler/base/vector.py index 8bf09f7d..6688462d 100644 --- a/compiler/base/vector.py +++ b/compiler/base/vector.py @@ -28,6 +28,7 @@ class vector(): else: self.x = float(x) self.y = float(y) + self._hash = hash((self.x,self.y)) def __str__(self): """ override print function output """ @@ -97,7 +98,7 @@ class vector(): Note: This assumes that you DON'T CHANGE THE VECTOR or it will break things. """ - return hash((self.x,self.y)) + return self._hash def snap_to_grid(self): self.x = self.snap_offset_to_grid(self.x) diff --git a/compiler/router/vector3d.py b/compiler/router/vector3d.py index 0d183021..066f843f 100644 --- a/compiler/router/vector3d.py +++ b/compiler/router/vector3d.py @@ -27,7 +27,7 @@ class vector3d(): self.x = x self.y = y self.z = z - + self._hash = hash((self.x,self.y,self.z)) def __str__(self): """ override print function output """ @@ -96,7 +96,7 @@ class vector3d(): Note: This assumes that you DON'T CHANGE THE VECTOR or it will break things. """ - return hash((self.x,self.y,self.z)) + return self._hash def __rsub__(self, other):