home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / bitvctr / readme.txt < prev   
Encoding:
Text File  |  1996-11-20  |  5.4 KB  |  169 lines

  1. Here's a simple class that fills a common need: A BitVector.
  2.  
  3. This software, and the included source code, is FREEWARE.
  4.  
  5. You may use it as you see fit in your own projects but you may 
  6. not re-sell the original or a derivative. If you redistribute 
  7. it you must include this disclaimer and all original copyright
  8. notices. 
  9.  
  10. No warranty is inferred or implied, as always seems to be the
  11. case with software these days. Use at your own risk. Keep away
  12. from small children. Don't exceed recommended dosage. I'm not
  13. liable, I'm not liable, I'm not liable.
  14.  
  15. It's not complete, or *extremely* well thought out I suppose,
  16. but it's a good starting point. You'll see some "TBD"s in the
  17. code which indicates that it's a work in progress.
  18.  
  19. There's not much code, and I haven't done any real docs on it
  20. yet, but it should be useful none-the-less and you can always
  21. e-mail questions to me.
  22.  
  23. I'd love to see people improve upon this work. Please keep me 
  24. posted if you do. If you should happen to change the behavior
  25. in a derivative version please change the class name so as not
  26. to cause problems with existing code.
  27.  
  28. Enjoy!
  29.  
  30. --Gregg Irwin [72450,676]
  31.  
  32. --------------------------------------------------------------
  33.  
  34. Q. What's new in Version 1.1? 
  35.  
  36. A. ╖ Bit property access. This lets you use normal array 
  37.      syntax to set and get bit values.
  38.  
  39.      BitVal = BV.Bit(1)
  40.      BV.Bit(1) = 1
  41.      
  42.    ╖ Error handler in NumElements Let procedure 
  43.  
  44. --------------------------------------------------------------
  45.  
  46. Q. What's a BitVector? 
  47.  
  48. A. It's just an array designed to store True/False values.
  49.  
  50. --------------------------------------------------------------
  51.  
  52. Q. Can't I just define an array of Boolean variables to do 
  53.    that?
  54.  
  55. A. Yes you can.
  56.  
  57. --------------------------------------------------------------
  58.  
  59. Q. Why would I want to use a BitVector instead of an
  60.    array of Boolean variables?
  61.  
  62. A. Size. Boolean variables are stored as 16-bit 
  63.    (2-byte) integers. If you have a small number of 
  64.    items to track then memory consumption may not be
  65.    a concern to you. If, however, you had 1,000,000
  66.    items to track then you might flinch a bit at using
  67.    2 meg of memory to do so. A BitVector uses only 1
  68.    bit per item, instead of 16 bits like a Boolean does.
  69.    To track 1,000,000 items you would only use 125K of
  70.    memory, rather than 2 meg.
  71.  
  72.    Under VB4/32 they may actually be stored as 32 bit
  73.    (i.e. long) integers if I recall correctly. The current
  74.    docs don't say so but it would make sense to make them
  75.    as fast as possible on 32 bit systems. Keeping things
  76.    aligned, etc.
  77.  
  78. --------------------------------------------------------------
  79.  
  80. Q. What's the downside?
  81.  
  82. A. Speed. Rather than referencing array variables directly
  83.    the BitVector has to do a bit of processing to identify
  84.    individual bits. Jim Mack has written routines in assembly
  85.    language (which are part of Microhelp Muscle) that should
  86.    be fast enough for *anybody*. Using a table to look up 
  87.    values could also speed things up a bit. There's a note
  88.    in the code about this idea.
  89.  
  90. --------------------------------------------------------------
  91.  
  92. Q. How do I use it?
  93.  
  94. A. It's easy.
  95.    
  96.    1. Dim a variable to hold the bit vector.
  97.  
  98.       Example: Dim BV As New BitVector
  99.  
  100.    2. Set the number of elements you want the BitVector to
  101.       hold using the NumElements property.
  102.  
  103.       Example: BV.NumElements = 25000
  104.  
  105.    3. Set, Get, Clear, Toggle, and Test bits by referencing 
  106.       their index.
  107.  
  108.       BV.SetBit 12345
  109.       BitVal = BV.GetBit 12345
  110.       BV.ClearBit 12345
  111.       BV.ToggleBit 12345
  112.       On = BV.IsBitSet 12345
  113.  
  114. --------------------------------------------------------------
  115.  
  116. Q. What's the difference between GetBit and IsBitSet?
  117.  
  118. A. GetBit returns the actual value of the bit (1 or 0) while
  119.    IsBitSet returns a boolean value of True or False.
  120.  
  121. --------------------------------------------------------------
  122.  
  123. Q. What if I want to set, or clear, all of the bits at once?
  124.  
  125. A. Simple. Use the SetAll or ClearAll methods.
  126.  
  127. --------------------------------------------------------------
  128.  
  129. Q. Why a class module?
  130.  
  131. A. Why not? It has a defined interface. It provides 
  132.    encapsulation. It allows you to create multiple instances
  133.    easily. It can be used as an OLE server. It can raise
  134.    errors effectively. 'nuff said?
  135.  
  136. --------------------------------------------------------------
  137.  
  138. Q. What if I forget how many elements are in a BitVector?
  139.  
  140. A. Use the NumElements method to find out.
  141.  
  142.    Example: ElCount = BV.NumElements
  143.  
  144. --------------------------------------------------------------
  145.  
  146. Q. What if I "grow" a BitVector (i.e. increase NumElements)?
  147.  
  148. A. It remembers the current bit states so you'll need to 
  149.    clear them manually if that's what you want. New bits will
  150.    be "off" initially.
  151.  
  152. --------------------------------------------------------------
  153.  
  154. Q. What if I have suggestions, requests, or improvements?
  155.  
  156. A. Send them to me and I'll get back to you as quickly as I 
  157.    can. Hopefully we can make it a community effort and build
  158.    up a good library of tools that we can all draw upon.
  159.  
  160. --------------------------------------------------------------
  161.  
  162. Q. What if it has a bug in it that costs me millions of 
  163.    dollars?
  164.  
  165. A. Re-read the disclaimer and let me know about the bug 
  166.    please.<g>
  167.  
  168. --------------------------------------------------------------
  169.