From 794441dc378097dcd2abcd0ebb7f2529c2505918 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Mon, 19 Feb 2007 02:45:41 +0000 Subject: [PATCH] * src/plugins/AncestorChart2.py: Use a dict instead of an array to use less memory. svn: r8164 --- ChangeLog | 4 ++++ src/plugins/AncestorChart2.py | 36 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c9dc7dda..61ee30122 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-02-18 Brian Matherly + * src/plugins/AncestorChart2.py: Use a dict instead of an array to use less + memory. + 2007-02-17 Anthon Pang * src/GrampsDb/_WriteGedcom.py: Fix encoding on output diff --git a/src/plugins/AncestorChart2.py b/src/plugins/AncestorChart2.py index 5e2638b71..c612c8688 100644 --- a/src/plugins/AncestorChart2.py +++ b/src/plugins/AncestorChart2.py @@ -77,12 +77,9 @@ class GenChart: def __init__(self,generations): self.generations = generations self.size = (2**(generations)) - self.array = [None]*(self.size) + self.array = {} self.map = {} self.compress_map = {} - - for i in range(0,(self.size)): - self.array[i] = [0]*generations self.max_x = 0 self.ad = (self.size,generations) @@ -92,6 +89,8 @@ class GenChart: y = index - (2**x) delta = int((self.size/(2**(x)))) new_y = int((delta/2) + (y)*delta) + if not new_y in self.array: + self.array[new_y] = {} self.array[new_y][x] = (value,index) self.max_x = max(x,self.max_x) self.map[value] = (new_y,x) @@ -119,40 +118,41 @@ class GenChart: return None def get_xy(self,x,y): - return self.array[y][x] + value = 0 + if y in self.array: + if x in self.array[y]: + value = self.array[y][x] + return value def set_xy(self,x,y,value): + if not y in self.array: + self.array[y] = {} self.array[y][x] = value def dimensions(self): - return (len(self.array),self.max_x+1) + return (max(self.array.keys()),self.max_x+1) def compress(self): new_map = {} - new_array = [] + new_array = {} old_y = 0 new_y = 0 - for i in self.array: - if i and self.not_blank(i): + for key in self.array.keys(): + i = self.array[key] + old_y = key + if self.not_blank(i.values()): self.compress_map[old_y] = new_y - new_array.append(i) + new_array[new_y] = i x = 0 for entry in i: - if entry: - new_map[entry] = (new_y,x) + new_map[entry] = (new_y,x) x =+ 1 new_y += 1 - old_y += 1 self.array = new_array self.map = new_map self.ad = (new_y,self.ad[1]) - def display(self): - index = 0 - for i in self.array: - index=index+1 - def not_blank(self,line): for i in line: if i and type(i) == tuple: