[elephant-devel] Newbie question: Index on collections

Marc klists at saphor.de
Tue Mar 18 04:50:07 UTC 2008


Ian Eslick wrote:
> The pset is probably your best bet.  Other collection objects have 
> more performance impact.  With a pset you can ask:
>
> is X a friend of Y?  (find-item X (friends Y)) => X | nil
>
> all people that X is friends of:
>
> (remove-nulls
>   (map-class 'people (lambda (y)
>                         (when (find-item X (friends Y))
>                            Y))
>              :collect t))
>
> This requires walking all person objects.  For larger DB's, you can 
> build your own 'many-to-many' relation table or waiting for the next 
> release which should do this for you.
Is there a time line (however preliminary) when this release might be
available?
>
> (defpclass friend-relation ()
>    ((first :accessor first :initarg :first :index t)
>     (second :accessor second :initarg :second :index t)))
>
> (defmethod add-friend-relation (x y)
>    (make-instance 'friend-relation :first x :second y))
>
> (defmethod friends-of (x)
>    (union (mapcar #'second (get-instances-by-slot 'friend-relation 
> 'first x))
>           (mapcar #'first (get-instances-by-slot 'friend-relation 
> 'second x))))
>
> Of course there are ways to do this more efficiently, but I think this 
> is the idea.
>
Many thanks for this guidance. That does, indeed, give me an idea of the
best way forward in our application.


Best regards,

Marc

>
>
> On Mar 16, 2008, at 11:06 PM, Marc wrote:
>
>> Hello!
>>
>> I fear that this may be a rather stupid newbie question, but neither 
>> from the documentation nor from the mailing list posts I got an idea 
>> as to the best practice for the following type of searches. Let's use 
>> an example akin to the one in the tutorial:
>>
>> (defpclass person ()
>> ((name :accessor name :index t)
>> (friends :accessor friends)) ;collection with names (say as strings) 
>> of the friends of this person
>> )
>>
>> Given a similar structure, what is the recommended way to handle 
>> queries of the type "find all persons that X is a friend of?" (i.e. 
>> queries on individual entries in slots that contain collections)? 
>> What would be the best data structure for the friends slot, assuming 
>> that the collection remains fairly stable over time (psets, lists or 
>> other collections)?
>>
>> Thanks in advance for any hint!
>>
>> Best regards,
>>
>> Marc
>>
>>
>>
>>
>> _______________________________________________
>> elephant-devel site list
>> elephant-devel at common-lisp.net
>> http://common-lisp.net/mailman/listinfo/elephant-devel
>
> _______________________________________________
> elephant-devel site list
> elephant-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/elephant-devel
>
>
>






More information about the elephant-devel mailing list