[Zope-dev] large PersistentMapping
Chris Withers
chrisw@nipltd.com
Wed, 15 Nov 2000 10:36:02 +0000
Talk to Tres Seaver about the observer interface and the event channel
stuff.
He has lots of ideas about this and I think it does pretty much what you
want...
cheers,
Chris
Robin Becker wrote:
>
> I'm trying to build a Reverse Cross Referencing Product. The idea is to
> enable documents to know which other documents in the Zope data base are
> pointing at them.
> I would like to use a persistent mapping to store the link information,
> but since eventually the object might be quite large will I get a
> performance hit when accessing only a small part of the object.
>
> It certainly seems to work for small instances, but I'm worried about
> what happens as my structure gets larger. Is there an alternate way to
> do this?
>
> The heart of the object are the methods
>
>
> def __init__(self, id, title):
> '''Initialise a new instance of RXRef'''
> self.id=str(id)
> self.title = str(title)
> self.title = title
> self._N = PersistentMapping()
>
> def addNode(self,n):
> '''Add a new node if not known'''
> N = self._N
> if not N.has_key(n): N[n]=[]
>
> def addLinks(self,src,DST):
> '''We have a single src and multiple destinations'''
> if type(DST) not in SEQTYPES: DST = [DST]
> N = self._N
> for dst in DST:
> self.addNode(dst)
> if src not in N[dst]: N[dst].append(src)
>
> def delLinks(self,src,DST):
> '''We have a single src and multiple destinations'''
> if type(DST) not in SEQTYPES: DST = [DST]
> N = self._N
> for dst in DST:
> if N.has_key(dst):
> if src in N[dst]:
> N[dst].remove(src)
> if N[dst]==[]: del N[dst]
>
> def getRLinks(self,dst):
> '''get links pointing to dst'''
> N = self._N
> return N.has_key(dst) and N[dst][:] or []
>
> --
> Robin Becker
>
> _______________________________________________
> Zope-Dev maillist - Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope )