Author: ArcRiley Date: 2007-07-05 04:33:48 -0400 (Thu, 05 Jul 2007) New Revision: 366
Added: trunk/pysoy/src/_internals/IndexTab.pxi Modified: trunk/pysoy/src/_internals/soy._internals.pxd trunk/pysoy/src/_internals/soy._internals.pyx Log: this is just the start of IndexTab Copied: trunk/pysoy/src/_internals/IndexTab.pxi (from rev 365, trunk/pysoy/src/_internals/Children.pxi) =================================================================== --- trunk/pysoy/src/_internals/IndexTab.pxi (rev 0) +++ trunk/pysoy/src/_internals/IndexTab.pxi 2007-07-05 08:33:48 UTC (rev 366) @@ -0,0 +1,92 @@ +# PySoy _internals.IndexTab class +# +# Copyright (C) 2007 Team PySoy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class IndexTab : + '''PySoy Indexed Lookup Table + + This is an extremely fast lookup table object. It's really only useful + for C-level code. + ''' + def __new__(self) : + self.size = 1 + self.current = 0 + self.list = <void **>py.PyMem_Malloc(sizeof(void *)) + + cdef void append(self, void *child) : + if self.size == self.current : + self.size = self.size * 2 + self.list = <void **>py.PyMem_Realloc(self.list, + sizeof(void *)*(self.size)) + self.list[self.current] = <void *>child + self.current = self.current + 1 + + cdef int index(self, void *child) : + cdef int i + for i from 0 <= i < self.current : + if self.list[i] == child : + return i + return -1 + + cdef void swap(self, int first, int second) : + cdef void *sibling + sibling = self.list[first] + self.list[first] = self.list[second] + self.list[second] = sibling + + cdef void down(self, void *child) : + cdef int index + index = self.index(child) + if index > 0 : + self.swap(index, index-1) + + cdef void up(self, void *child) : + cdef int index + index = self.index(child) + if index == -1 : + return + if index < self.current-1 : + self.swap(index, index+1) + + cdef void top(self, void *child) : + cdef int index + index = self.index(child) + if index == -1 : + return + if index < self.current-1 : + self.swap(index, self.current-1) + + cdef void bottom(self, void *child) : + cdef int index + index = self.index(child) + if index > 0 : + self.swap(index, 0) + + cdef void remove(self, void *child) : + cdef int i + cdef int index + index = self.index(child) + if index == -1 : + return + for i from index <= i < (self.current-1) : + self.list[i] = self.list[i+1] + self.current = self.current - 1 + + def __dealloc__(self) : + py.PyMem_Free(self.list) + py.PyThread_free_lock(self.mutex) Modified: trunk/pysoy/src/_internals/soy._internals.pxd =================================================================== --- trunk/pysoy/src/_internals/soy._internals.pxd 2007-07-05 08:12:15 UTC (rev 365) +++ trunk/pysoy/src/_internals/soy._internals.pxd 2007-07-05 08:33:48 UTC (rev 366) @@ -34,6 +34,19 @@ cdef void bottom ( self, void* ) cdef void remove ( self, void* ) +cdef class IndexTab : + cdef int size + cdef int current + cdef void **list + cdef void append ( self, void* ) + cdef int index ( self, void* ) + cdef void swap ( self, int, int ) + cdef void up ( self, void* ) + cdef void down ( self, void* ) + cdef void top ( self, void* ) + cdef void bottom ( self, void* ) + cdef void remove ( self, void* ) + cdef class Loadable : cdef int _load(self, void *data) cdef int _save(self, void *data) Modified: trunk/pysoy/src/_internals/soy._internals.pyx =================================================================== --- trunk/pysoy/src/_internals/soy._internals.pyx 2007-07-05 08:12:15 UTC (rev 365) +++ trunk/pysoy/src/_internals/soy._internals.pyx 2007-07-05 08:33:48 UTC (rev 366) @@ -27,4 +27,5 @@ __version__ = 'Trunk (r'+'$Rev$'[6:-2]+')' include "Children.pxi" +include "IndexTab.pxi" include "Loadable.pxi" _______________________________________________ PySoy-SVN mailing list [email protected] http://www.pysoy.org/mailman/listinfo/pysoy-svn
