Mail Archives: djgpp/1999/10/20/12:43:50
On Tue, 19 Oct 1999, Damian Yerrick wrote:
> Hammy <darren AT grayce DOT freeserve DOT co DOT uk> wrote in message
> news:7uitf2$qor$1 AT news8 DOT svr DOT pol DOT co DOT uk...
> > Probably not the best newsgroup but heres my problem.
> > Im trying to write an event manager for a mouse. The idea
> > I have so far is this: i have created a structure that holds the
> > coordinates of rectangles for which a mouse can click in a
> > trigger an event. Also in the struct I have a byte for the button
>
> Limit yourself to 128 buttons on screen? I'd use an int.
A byte can support 255 buttons. How many buttons can you feasibly
have on screen without bewildering people?
But I do agree that, if there's no good reason to use a byte, an int
should be the default choice.
> > I have this structure as a linked list and have ordered it in
> > active/disable, now, i can image this being rather slow the more events i
> > have. So, does anyone know of the a better way to do this?
>
> qsort() the rectangles by top coordinate and use a
> bsearch().
For small numbers of items, such as what we are talking here, it
usually doesn't pay off to sort them. Linear search through the
linked list should be enough. Later, if the program seems to run
slowly, profile it, and only replace the search algorithm if the
profile says that search is the hot spot. (I don't expect that to be
the case, for such a short list.)
- Raw text -