Re: [circle][code] Re: Bitvectors

From: Henrik Stuart (hstuart@geocities.com)
Date: 01/05/02


Greetings,

> I think I found stuff broken...

>>    #define NUM_AFFECT_VECTORS     (NUM_AFFECTS % (sizeof(long) * 8))

> I think you need to increment the value of NUM_AFFECT_VECTORS
> otherwise the array affected_by will almost always be an entry short
> almost all of the time. also shouldn't that be a divison and not a modulos.
>>
>>    This is how many bitvectors you need to have in your array. Then in
>>    the struct change: long affected_by; to long
>>    affected_by[NUM_AFFECT_VECTORS];
>>
> ::snip::
> How about say this implentation instead:

> #define NUM_AFFECT_VECTORS     (1+NUM_AFFECTS/32)
> affected_by[NUM_AFFECT_VECTORS];

> #define SET_AFFECT(ch,flag) (((ch)->char_specials.saved.\
>    affected_by[((flag) /32)]) = (1 << ((flag) %32)))
> #define TOGGLE_AFFECT(ch,flag) (((ch)->char_specials.saved.\
>    affected_by[((flag) /32)]) ^= (1 << ((flag) %32)))
> #define REMOVE_AFFECT(ch,flag) (((ch)->char_specials.saved.\
>    affected_by[((flag) /32)]) &= ~(1 << ((flag) %32)))

   Hummm, yup. :o)  Never code when you haven't slept for two days,
   heh. Granted, it's (sizeof(long)*8) that you need to divide and do
   modulo with. As for NUM_AFFECT_VECTORS it needs to be incremented
   with one as you point out. As for using 32 instead of the size
   let's see.... now... to use (sizeof(long)*8) in 7 places and make
   it platform independent or use 32 and limit it to 32-bit
   architectures? That's the reason you use (sizeof(long)*8).

   Anyway, thanks for pointing out the blatant error, should've seen
   that myself. :o)

--
Yours truly,
  Henrik Stuart (http://www.unprompted.com/hstuart/)

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT