From: Eli Zaretskii Newsgroups: comp.os.msdos.djgpp Subject: Re: Mouse Events Problem Date: Wed, 20 Oct 1999 14:00:12 +0200 Organization: NetVision Israel Lines: 32 Message-ID: References: <7uitf2$qor$1 AT news8 DOT svr DOT pol DOT co DOT uk> <7uiv4d$6bq$1 AT solomon DOT cs DOT rose-hulman DOT edu> NNTP-Posting-Host: is.elta.co.il Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: news.netvision.net.il 940420733 20727 199.203.121.2 (20 Oct 1999 11:58:53 GMT) X-Complaints-To: abuse AT netvision DOT net DOT il NNTP-Posting-Date: 20 Oct 1999 11:58:53 GMT X-Sender: eliz AT is In-Reply-To: <7uiv4d$6bq$1@solomon.cs.rose-hulman.edu> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Tue, 19 Oct 1999, Damian Yerrick wrote: > Hammy 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.)