[KinoSearch] adding a proximity scorer - Boilerplater
Marvin Humphrey
marvin at rectangular.com
Sat Jun 16 16:26:28 PDT 2007
On Jun 16, 2007, at 12:05 AM, Nathan Kurz wrote:
> I'm going with this for now, which seems reasonable to me:
>
> /* ADOPT is an alternative to CREATE for a subclass contructor that
> wants to
> start where the parent constructor left off. For example:
> SubClass *SubClass_new(parent_args, new_arg) {
> ADOPT(self, Parent_new(parent_args), SubClass, SUBCLASS);
> self->var = new_arg;
> return self;
> }
> */
> #define ADOPT(var, instance, type, vtable) \
> type *var = (type *) (instance); \
> var->_ = &(vtable); \
> var = KINO_REALLOCATE(var, 1, type);
>
> Does it seem like this would work?
Your approach is probably cleaner than the one I've taken, which has
been to create two functions: Parent_new() and Parent_init_base().
An example taken from BitVector is pasted below my sig. DelDocs,
which is a subclass of BitVector, supplies its own memory chunk to
BitVec_init_base() instead of reallocating an instance returned by
BitVec_new() -- avoiding the expense of double allocation.
However, I can see doing things your way by default, then going to
the two-function setup only for performance-critical constructors.
There aren't very many of those -- and DelDocs_new() probably isn't
one of them. :)
What I really want to do, though, is figure out how to implement KS
objects using the inside-out object model. I believe that this is
the key to realizing the goals I've laid out for subclassing Scorer.
int
SubClass_new(parent_args, new_arg) {
int me = Parent_new(parent_args);
allocate_and_store(me, new_arg);
return me;
}
It can't be quite so simple, but that's the general idea.
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
More information about the kinosearch
mailing list