You make some good points here and you are making me
think in a new direction.
> 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.
Actually that opens a lot of doors. If I want to do
conditional statements I can just iterate through the
map starting at the begining to the end because of
this ordering.
Also, it will be easy at runtime to allow the user of
the api to change the ordering of the map's keys
through configuration as well as specify if they want
to use the map's "find" operator or conditional
statements.
> Yes, but this is code you keep on the same unit of
> the
> tag itself. The other way you have to go back to the
> createTag() function each time you add a new tag,
> which means at least one extra unit to recompile.
Agreed. This is a difficult design decision for me to
make and requires one extra step of discipline to
ensure that I add each new tag to that particular
method.
> In that specific case it is an ugly hack, yes. But I
> know dynamic libraries provide better ways to run
> code
> at load time, and since you said you intended to use
> DLL's on your project...
>
> Anyway, this is how I would do things, but what do I
> know? If I was such a great C++ programmer I
> wouldn't
> do everything in Java. ^_^'
>
You sound like a pretty proficient C++'er.
Certainly using dll's opens more options for loading
at runtime but not enought to make this solution any
more elegant as far as I can see.
To myself, cosmetically, having a string-to-class
factory method does not seem that horrible. For
creators of the custom dll for the custom tags they
will have to inherit from the factory method and add
their new's to their custom string-to-class method.
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.
--- Helio Perroni Filho <
xperroni@...> wrote:
> --- mehri <
foreverlinux@...> escreveu:
>
> > > Hence my idea of providing factory functions for
> each
> > > tag, mapping the tag names to pointers for the
> factoy
> > > functions, and then retrieving the pointers from
> a
> map
> > > as the tags are read from the XML document. As I
> > > exposed, it is not as simple as reflection, but
> it
> > > can be done, and is more efficient than
> conditional
> > > chains.
> >
> > Agreed when considering the overall worse case
> > senario using Big-O. O(log n) with a balanced
> tree
> > (std::map) versus the worst case run time of a
> conditional
> > statement O(n)
> >
> > Now what about the best case senario? With a
> > std::map, you still get Omega(log n) but with a
> > conditional statement you end up with Omega(1).
>
>
> > Certain tags are going to occur higher in
> frequency
> > on average than others so I group those at the
> top.
> > The overall runtime is actually a bit quicker than
> if I
> > were to search a map since I know ahead of time
> > which tags occur at a higher frequency.
>
> Some tags are indeed bound to be on the top of the
> frequency list, such as (category), (pattern) and
> (template); others can appear very often in some
> AIML
> sets and not so much in others. With a map, you
> could
> eventually provide features to adapt the ordering
> according to run-time hit frequency, or provide a
> config file for the botmaster to define the
> priorities.
>
> > > // Ugly hack to allow load-time execution of
> code.
> > > class CategoryRegister
> > > {
> > > public:
> > > CategoryRegister()
> > > {
> > > factories["Category"] = newCategory;
> > > }
> > > }
> >
> > So you still have to write code to say, new
> Category
> > here? With each new tag you add you still have to
> > hand code the "new TagName"?
>
> Yes, but this is code you keep on the same unit of
> the
> tag itself. The other way you have to go back to the
> createTag() function each time you add a new tag,
> which means at least one extra unit to recompile.
>
> > That and you even say Ugly hack in your comments.
>
> In that specific case it is an ugly hack, yes. But I
> know dynamic libraries provide better ways to run
> code
> at load time, and since you said you intended to use
> DLL's on your project...
>
> Anyway, this is how I would do things, but what do I
> know? If I was such a great C++ programmer I
> wouldn't
> do everything in Java. ^_^'
>
> --
> Ja mata ne.
> Helio Perroni Filho
>
>
>
>
>
>
>
>
>
>
_______________________________________________________
>
> Yahoo! doce lar. Faça do Yahoo! sua homepage.
>
http://br.yahoo.com/homepageset.html
>
> _______________________________________________
> alicebot-developer mailing list
>
alicebot-developer@...
>
http://list.alicebot.org/mailman/listinfo/alicebot-developer>
.................................................o' \,=./ `o
Mehri (o o)
---=--=---=--=--=---=--=--=--=--=---=--=--=-----ooO--(_)--Ooo---
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
alicebot-developer mailing list
alicebot-developer@...
http://list.alicebot.org/mailman/listinfo/alicebot-developer