Currently, I do something along the lines of the following on the results on get-instance[s]-by-XXX functions: <div><br></div><div>(remove-if #'(lambda (x) (not (member ',class-name (mapcar #'class-name (sb-mop:class-precedence-list x))))) lst :key #'class-of)<br>
<div>if I want results on the whole inheritance chain, or</div><div><br></div><div>(remove-if #'(lambda (x) (not (equal ',class-name x)))) lst :key #'class-of)</div><div>if I want result on the specific class.</div>
<div><br></div><div>Now I know that efficiency is the issue here, but my (naive , since I havent had performance problems yet) response to that is that since the the search is indexed anyway, does it really matter?</div><div>
I mean since the complexity of the search is logarithmic wont the separate hierachical index implementation you propose have diminishing returns? This is just off the top of my head, dont throw stuff at me if I am saying something odviously stupid.</div>
<div><br></div><div>Thanks, Vassilis.</div><div><br></div><div><br><div class="gmail_quote">On Wed, Apr 27, 2011 at 12:12 AM, Alex Mizrahi <span dir="ltr"><<a href="mailto:killerstorm@newmail.ru">killerstorm@newmail.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Index inheritance is a nice feature for the case when you have several<br>
sub-classes inheriting from a common base class and you want to lookup<br>
instances by a slot value regadless of the sub-class.<br>
E.g. if super-from and mega-frob inherit from frob base class you can look<br>
up any kind of frob by frob-id if it is inherited.<br>
<br>
But what's about the case where you want to be able to do queries both among<br>
all subclasses and for a specific sub-class?<br>
<br>
id slot is probably a bad example since it is likely to be unique, so let's<br>
say we have frob-style slot.<br>
<br>
Sometimes I want get any kind of frob with a specific style:<br>
<br>
  (ele:get-instances-by-value 'frob 'frob-style "vanilla")<br>
<br>
Sometimes I want to get instances of a specific class with a certain<br>
property:<br>
<br>
  (ele:get-instances-by-value 'super-frob 'frob-style "vanilla")<br>
<br>
But if slot frob-style has inherited index it doesn't matter what specific<br>
class is passed to get-instances-by-value, it can return frobs and<br>
mega-frobs even if you're asking for super-frobs.<br>
<br>
I think ideally this would be resolved with a new type of 'hierarchical'<br>
slot indices where instances will be indexed in many indices at once -- when<br>
you make super-frob instance it will be indexed by frob-style both in<br>
super-frob and frob index (and, generally, in all super-classes). In this<br>
case get-instances-by-... semantics will be cleaner.<br>
<br>
But perhaps that would be rather hard to implement.<br>
<br>
As a quick fix, maybe we can filter instances on get-instances-by-... or<br>
map-inverted-index level?<br>
These functions have information about actual class so filtering instances<br>
using type-of should be trivial.<br>
<br>
Of course that will have sub-optimal performance as more instances will be<br>
pulled from database.<br>
But it is better than nothing and it fixes non-intuitive behaviour<br>
(instances of wrong type are returned if you look at it from API point of<br>
view).<br>
<br>
Users might achieve this functionality using derived indices -- say, normal<br>
frob-style slot won't have inherited index but derived slot frob-style* will<br>
be inherited and will just mirror frob-style. Thus when you want to lookup<br>
among all sub-classes you should use frob-style* instead of frob-style.<br>
But this looks a bit cumbersome in class definitions.<br>
<br>
<br>
<br>
_______________________________________________<br>
elephant-devel site list<br>
<a href="mailto:elephant-devel@common-lisp.net">elephant-devel@common-lisp.net</a><br>
<a href="http://common-lisp.net/mailman/listinfo/elephant-devel" target="_blank">http://common-lisp.net/mailman/listinfo/elephant-devel</a><br>
</blockquote></div><br></div></div>