* src/plugins/AncestorChart2.py: Use a dict instead of an array to use less memory.

svn: r8164
This commit is contained in:
Brian Matherly 2007-02-19 02:45:41 +00:00
parent a0991f5a4c
commit 794441dc37
2 changed files with 22 additions and 18 deletions

View File

@ -1,3 +1,7 @@
2007-02-18 Brian Matherly <brian@gramps-project.org>
* src/plugins/AncestorChart2.py: Use a dict instead of an array to use less
memory.
2007-02-17 Anthon Pang <apang@softwaredevelopment.ca> 2007-02-17 Anthon Pang <apang@softwaredevelopment.ca>
* src/GrampsDb/_WriteGedcom.py: Fix encoding on output * src/GrampsDb/_WriteGedcom.py: Fix encoding on output

View File

@ -77,13 +77,10 @@ class GenChart:
def __init__(self,generations): def __init__(self,generations):
self.generations = generations self.generations = generations
self.size = (2**(generations)) self.size = (2**(generations))
self.array = [None]*(self.size) self.array = {}
self.map = {} self.map = {}
self.compress_map = {} self.compress_map = {}
for i in range(0,(self.size)):
self.array[i] = [0]*generations
self.max_x = 0 self.max_x = 0
self.ad = (self.size,generations) self.ad = (self.size,generations)
@ -92,6 +89,8 @@ class GenChart:
y = index - (2**x) y = index - (2**x)
delta = int((self.size/(2**(x)))) delta = int((self.size/(2**(x))))
new_y = int((delta/2) + (y)*delta) 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.array[new_y][x] = (value,index)
self.max_x = max(x,self.max_x) self.max_x = max(x,self.max_x)
self.map[value] = (new_y,x) self.map[value] = (new_y,x)
@ -119,40 +118,41 @@ class GenChart:
return None return None
def get_xy(self,x,y): 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): def set_xy(self,x,y,value):
if not y in self.array:
self.array[y] = {}
self.array[y][x] = value self.array[y][x] = value
def dimensions(self): def dimensions(self):
return (len(self.array),self.max_x+1) return (max(self.array.keys()),self.max_x+1)
def compress(self): def compress(self):
new_map = {} new_map = {}
new_array = [] new_array = {}
old_y = 0 old_y = 0
new_y = 0 new_y = 0
for i in self.array: for key in self.array.keys():
if i and self.not_blank(i): i = self.array[key]
old_y = key
if self.not_blank(i.values()):
self.compress_map[old_y] = new_y self.compress_map[old_y] = new_y
new_array.append(i) new_array[new_y] = i
x = 0 x = 0
for entry in i: for entry in i:
if entry: new_map[entry] = (new_y,x)
new_map[entry] = (new_y,x)
x =+ 1 x =+ 1
new_y += 1 new_y += 1
old_y += 1
self.array = new_array self.array = new_array
self.map = new_map self.map = new_map
self.ad = (new_y,self.ad[1]) 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): def not_blank(self,line):
for i in line: for i in line:
if i and type(i) == tuple: if i and type(i) == tuple: