[alicebot-developer] Dynamic tag instantiation in C++ (was: ChatterBean 00.007 is now available)

Helio Perroni Filho xperroni at yahoo.com
Wed Dec 14 11:52:06 PST 2005


--- mehri <foreverlinux at yahoo.com> escreveu:

> > Not if the (key, value) pairs are sorted
> > appropriately, something you can do with std::map,
> > admitedly with some extra work.
> 
> Hmmm....This stumped me for a second.
> 
> But what you are talking about is changing the
> comparison operator for the keys correct?  So the
> map is ordered with higher frequency tags closer to
the
> begining.

Yes, that is the idea. Actually with a reasonably good
comparison operator, you could achieve better
assintotic time with this approach than with a
conditional chain -- whose time is O(n/2) in the
normal case, whereas a binary tree search would yield
O(lg n/2).

> What I do have a question about for this methodology
> would be this portion of your pseudocode:
> 
> > class CategoryRegister
> > {
> > public:
> >   CategoryRegister()
> >   {
> >     factories["Category"] = newCategory;
> >   }
> > }
> 
> You still have to write the "new Category" in a
> seperate class for registeration?  Regardless of how
> well you design your subclass you still have to go
> to a different class to add code?
> 
> That's my hangup.  No matter how clever, you still
> have go outside of your subclass to add code for the
> engine to recognize your new Tag class.

In Java, you could write the registration code into a
static block, which  would be executed at
class-loading time. C++ doesn't have such a feature as
far as I know, so we have to hack it with static field
initialization. You could conceivably move the
registration code (class and field) into the tag
class, but I can't see exactly what that would buy us,
with the possible exception of better-looking code.




	



	
		
_______________________________________________________ 
Yahoo! doce lar. Faça do Yahoo! sua homepage. 
http://br.yahoo.com/homepageset.html 



More information about the alicebot-developer mailing list