~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_bitmap.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
 
  Handling of uchar arrays as large bitmaps.
 
17
  Handling of unsigned char arrays as large bitmaps.
18
18
 
19
19
  API limitations (or, rather asserted safety assumptions,
20
20
  to encourage correct programming)
36
36
*/
37
37
 
38
38
#include "mysys_priv.h"
39
 
#include <my_bitmap.h>
40
 
#include <m_string.h>
41
 
#include <my_bit.h>
 
39
#include <mysys/my_bitmap.h>
 
40
#include <mystrings/m_string.h>
 
41
#include <mysys/my_bit.h>
42
42
 
43
43
void create_last_word_mask(MY_BITMAP *map)
44
44
{
62
62
  map->last_word_ptr= map->bitmap + no_words_in_map(map)-1;
63
63
  switch (no_bytes_in_map(map) & 3) {
64
64
  case 1:
65
 
    map->last_word_mask= ~0U;
 
65
    map->last_word_mask= UINT32_MAX;
66
66
    ptr[0]= mask;
67
67
    return;
68
68
  case 2:
69
 
    map->last_word_mask= ~0U;
 
69
    map->last_word_mask= UINT32_MAX;
70
70
    ptr[0]= 0;
71
71
    ptr[1]= mask;
72
72
    return;
73
73
  case 3:
74
 
    map->last_word_mask= 0U;
 
74
    map->last_word_mask= 0;
75
75
    ptr[2]= mask;
76
76
    ptr[3]= 0xFFU;
77
77
    return;
96
96
}
97
97
 
98
98
 
99
 
bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
 
99
bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint32_t n_bits,
100
100
                    bool thread_safe __attribute__((unused)))
101
101
{
102
 
  DBUG_ENTER("bitmap_init");
103
102
  if (!buf)
104
103
  {
105
 
    uint size_in_bytes= bitmap_buffer_size(n_bits);
106
 
    uint extra= 0;
 
104
    uint32_t size_in_bytes= bitmap_buffer_size(n_bits);
 
105
    uint32_t extra= 0;
107
106
    if (thread_safe)
108
107
    {
109
108
      size_in_bytes= ALIGN_SIZE(size_in_bytes);
111
110
    }
112
111
    map->mutex= 0;
113
112
    if (!(buf= (my_bitmap_map*) my_malloc(size_in_bytes+extra, MYF(MY_WME))))
114
 
      DBUG_RETURN(1);
 
113
      return(1);
115
114
    if (thread_safe)
116
115
    {
117
116
      map->mutex= (pthread_mutex_t *) ((char*) buf + size_in_bytes);
120
119
  }
121
120
  else
122
121
  {
123
 
    DBUG_ASSERT(thread_safe == 0);
 
122
    assert(thread_safe == 0);
124
123
  }
125
124
 
126
125
  map->bitmap= buf;
127
126
  map->n_bits= n_bits;
128
127
  create_last_word_mask(map);
129
128
  bitmap_clear_all(map);
130
 
  DBUG_RETURN(0);
 
129
  return(0);
131
130
}
132
131
 
133
132
 
134
133
void bitmap_free(MY_BITMAP *map)
135
134
{
136
 
  DBUG_ENTER("bitmap_free");
137
135
  if (map->bitmap)
138
136
  {
139
137
    if (map->mutex)
140
138
      pthread_mutex_destroy(map->mutex);
141
 
    my_free((char*) map->bitmap, MYF(0));
 
139
    free((char*) map->bitmap);
142
140
    map->bitmap=0;
143
141
  }
144
 
  DBUG_VOID_RETURN;
 
142
  return;
145
143
}
146
144
 
147
145
 
158
156
    !=0  bit was set
159
157
*/
160
158
 
161
 
bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit)
 
159
bool bitmap_fast_test_and_set(MY_BITMAP *map, uint32_t bitmap_bit)
162
160
{
163
 
  uchar *value= ((uchar*) map->bitmap) + (bitmap_bit / 8);
164
 
  uchar bit= 1 << ((bitmap_bit) & 7);
165
 
  uchar res= (*value) & bit;
 
161
  unsigned char *value= ((unsigned char*) map->bitmap) + (bitmap_bit / 8);
 
162
  unsigned char bit= 1 << ((bitmap_bit) & 7);
 
163
  unsigned char res= (*value) & bit;
166
164
  *value|= bit;
167
165
  return res;
168
166
}
181
179
    !=0  bit was set
182
180
*/
183
181
 
184
 
bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit)
 
182
bool bitmap_test_and_set(MY_BITMAP *map, uint32_t bitmap_bit)
185
183
{
186
184
  bool res;
187
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
185
  assert(map->bitmap && bitmap_bit < map->n_bits);
188
186
  bitmap_lock(map);
189
187
  res= bitmap_fast_test_and_set(map, bitmap_bit);
190
188
  bitmap_unlock(map);
204
202
    !=0  bit was set
205
203
*/
206
204
 
207
 
bool bitmap_fast_test_and_clear(MY_BITMAP *map, uint bitmap_bit)
 
205
bool bitmap_fast_test_and_clear(MY_BITMAP *map, uint32_t bitmap_bit)
208
206
{
209
 
  uchar *byte= (uchar*) map->bitmap + (bitmap_bit / 8);
210
 
  uchar bit= 1 << ((bitmap_bit) & 7);
211
 
  uchar res= (*byte) & bit;
 
207
  unsigned char *byte= (unsigned char*) map->bitmap + (bitmap_bit / 8);
 
208
  unsigned char bit= 1 << ((bitmap_bit) & 7);
 
209
  unsigned char res= (*byte) & bit;
212
210
  *byte&= ~bit;
213
211
  return res;
214
212
}
215
213
 
216
214
 
217
 
bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit)
 
215
bool bitmap_test_and_clear(MY_BITMAP *map, uint32_t bitmap_bit)
218
216
{
219
217
  bool res;
220
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
218
  assert(map->bitmap && bitmap_bit < map->n_bits);
221
219
  bitmap_lock(map);
222
220
  res= bitmap_fast_test_and_clear(map, bitmap_bit);
223
221
  bitmap_unlock(map);
225
223
}
226
224
 
227
225
 
228
 
uint bitmap_set_next(MY_BITMAP *map)
 
226
uint32_t bitmap_set_next(MY_BITMAP *map)
229
227
{
230
 
  uint bit_found;
231
 
  DBUG_ASSERT(map->bitmap);
 
228
  uint32_t bit_found;
 
229
  assert(map->bitmap);
232
230
  if ((bit_found= bitmap_get_first(map)) != MY_BIT_NONE)
233
231
    bitmap_set_bit(map, bit_found);
234
232
  return bit_found;
235
233
}
236
234
 
237
235
 
238
 
void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size)
 
236
void bitmap_set_prefix(MY_BITMAP *map, uint32_t prefix_size)
239
237
{
240
 
  uint prefix_bytes, prefix_bits, d;
241
 
  uchar *m= (uchar *)map->bitmap;
 
238
  uint32_t prefix_bytes, prefix_bits, d;
 
239
  unsigned char *m= (unsigned char *)map->bitmap;
242
240
 
243
 
  DBUG_ASSERT(map->bitmap &&
244
 
              (prefix_size <= map->n_bits || prefix_size == (uint) ~0));
 
241
  assert(map->bitmap &&
 
242
              (prefix_size <= map->n_bits || prefix_size == UINT32_MAX));
245
243
  set_if_smaller(prefix_size, map->n_bits);
246
244
  if ((prefix_bytes= prefix_size / 8))
247
245
    memset(m, 0xff, prefix_bytes);
249
247
  if ((prefix_bits= prefix_size & 7))
250
248
    *m++= (1 << prefix_bits)-1;
251
249
  if ((d= no_bytes_in_map(map)-prefix_bytes))
252
 
    bzero(m, d);
 
250
    memset(m, 0, d);
253
251
}
254
252
 
255
253
 
256
 
bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size)
 
254
bool bitmap_is_prefix(const MY_BITMAP *map, uint32_t prefix_size)
257
255
{
258
 
  uint prefix_bits= prefix_size & 0x7, res;
259
 
  uchar *m= (uchar*)map->bitmap;
260
 
  uchar *end_prefix= m+prefix_size/8;
261
 
  uchar *end;
262
 
  DBUG_ASSERT(m && prefix_size <= map->n_bits);
 
256
  uint32_t prefix_bits= prefix_size & 0x7, res;
 
257
  unsigned char *m= (unsigned char*)map->bitmap;
 
258
  unsigned char *end_prefix= m+prefix_size/8;
 
259
  unsigned char *end;
 
260
  assert(m && prefix_size <= map->n_bits);
263
261
  end= m+no_bytes_in_map(map);
264
262
 
265
263
  while (m < end_prefix)
311
309
{
312
310
  my_bitmap_map *m1= map1->bitmap, *m2= map2->bitmap, *end;
313
311
 
314
 
  DBUG_ASSERT(map1->bitmap && map2->bitmap &&
 
312
  assert(map1->bitmap && map2->bitmap &&
315
313
              map1->n_bits==map2->n_bits);
316
314
 
317
315
  end= map1->last_word_ptr;
331
329
{
332
330
  my_bitmap_map *m1= map1->bitmap, *m2= map2->bitmap, *end;
333
331
 
334
 
  DBUG_ASSERT(map1->bitmap && map2->bitmap &&
 
332
  assert(map1->bitmap && map2->bitmap &&
335
333
              map1->n_bits==map2->n_bits);
336
334
 
337
335
  end= map1->last_word_ptr;
349
347
void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2)
350
348
{
351
349
  my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end;
352
 
  uint len= no_words_in_map(map), len2 = no_words_in_map(map2);
353
 
 
354
 
  DBUG_ASSERT(map->bitmap && map2->bitmap);
355
 
 
356
 
  end= to+min(len,len2);
 
350
  uint32_t len= no_words_in_map(map), len2 = no_words_in_map(map2);
 
351
 
 
352
  assert(map->bitmap && map2->bitmap);
 
353
 
 
354
  end= to+cmin(len,len2);
357
355
  *map2->last_word_ptr&= ~map2->last_word_mask; /*Clear last bits in map2*/
358
356
  while (to < end)
359
357
    *to++ &= *from++;
387
385
    void
388
386
*/
389
387
 
390
 
void bitmap_set_above(MY_BITMAP *map, uint from_byte, uint use_bit)
 
388
void bitmap_set_above(MY_BITMAP *map, uint32_t from_byte, uint32_t use_bit)
391
389
{
392
 
  uchar use_byte= use_bit ? 0xff : 0;
393
 
  uchar *to= (uchar *)map->bitmap + from_byte;
394
 
  uchar *end= (uchar *)map->bitmap + (map->n_bits+7)/8;
 
390
  unsigned char use_byte= use_bit ? 0xff : 0;
 
391
  unsigned char *to= (unsigned char *)map->bitmap + from_byte;
 
392
  unsigned char *end= (unsigned char *)map->bitmap + (map->n_bits+7)/8;
395
393
 
396
394
  while (to < end)
397
395
    *to++= use_byte;
401
399
void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2)
402
400
{
403
401
  my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end;
404
 
  DBUG_ASSERT(map->bitmap && map2->bitmap &&
 
402
  assert(map->bitmap && map2->bitmap &&
405
403
              map->n_bits==map2->n_bits);
406
404
 
407
405
  end= map->last_word_ptr;
415
413
{
416
414
  my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end;
417
415
 
418
 
  DBUG_ASSERT(map->bitmap && map2->bitmap &&
 
416
  assert(map->bitmap && map2->bitmap &&
419
417
              map->n_bits==map2->n_bits);
420
418
  end= map->last_word_ptr;
421
419
 
427
425
void bitmap_xor(MY_BITMAP *map, const MY_BITMAP *map2)
428
426
{
429
427
  my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end= map->last_word_ptr;
430
 
  DBUG_ASSERT(map->bitmap && map2->bitmap &&
 
428
  assert(map->bitmap && map2->bitmap &&
431
429
              map->n_bits==map2->n_bits);
432
430
  while (to <= end)
433
431
    *to++ ^= *from++;
438
436
{
439
437
  my_bitmap_map *to= map->bitmap, *end;
440
438
 
441
 
  DBUG_ASSERT(map->bitmap);
 
439
  assert(map->bitmap);
442
440
  end= map->last_word_ptr;
443
441
 
444
442
  while (to <= end)
446
444
}
447
445
 
448
446
 
449
 
uint bitmap_bits_set(const MY_BITMAP *map)
 
447
uint32_t bitmap_bits_set(const MY_BITMAP *map)
450
448
{  
451
 
  uchar *m= (uchar*)map->bitmap;
452
 
  uchar *end= m + no_bytes_in_map(map);
453
 
  uint res= 0;
 
449
  unsigned char *m= (unsigned char*)map->bitmap;
 
450
  unsigned char *end= m + no_bytes_in_map(map);
 
451
  uint32_t res= 0;
454
452
 
455
 
  DBUG_ASSERT(map->bitmap);
 
453
  assert(map->bitmap);
456
454
  *map->last_word_ptr&= ~map->last_word_mask; /*Reset last bits to zero*/
457
455
  while (m < end)
458
 
    res+= my_count_bits_ushort(*m++);
 
456
    res+= my_count_bits_uint16(*m++);
459
457
  return res;
460
458
}
461
459
 
464
462
{
465
463
  my_bitmap_map *to= map->bitmap, *from= map2->bitmap, *end;
466
464
 
467
 
  DBUG_ASSERT(map->bitmap && map2->bitmap &&
 
465
  assert(map->bitmap && map2->bitmap &&
468
466
              map->n_bits==map2->n_bits);
469
467
  end= map->last_word_ptr;
470
468
  while (to <= end)
472
470
}
473
471
 
474
472
 
475
 
uint bitmap_get_first_set(const MY_BITMAP *map)
 
473
uint32_t bitmap_get_first_set(const MY_BITMAP *map)
476
474
{
477
 
  uchar *byte_ptr;
478
 
  uint i,j,k;
 
475
  unsigned char *byte_ptr;
 
476
  uint32_t i,j,k;
479
477
  my_bitmap_map *data_ptr, *end= map->last_word_ptr;
480
478
 
481
 
  DBUG_ASSERT(map->bitmap);
 
479
  assert(map->bitmap);
482
480
  data_ptr= map->bitmap;
483
481
  *map->last_word_ptr &= ~map->last_word_mask;
484
482
 
486
484
  {
487
485
    if (*data_ptr)
488
486
    {
489
 
      byte_ptr= (uchar*)data_ptr;
 
487
      byte_ptr= (unsigned char*)data_ptr;
490
488
      for (j=0; ; j++, byte_ptr++)
491
489
      {
492
490
        if (*byte_ptr)
496
494
            if (*byte_ptr & (1 << k))
497
495
              return (i*32) + (j*8) + k;
498
496
          }
499
 
          DBUG_ASSERT(0);
 
497
          assert(0);
500
498
        }
501
499
      }
502
 
      DBUG_ASSERT(0);
 
500
      assert(0);
503
501
    }
504
502
  }
505
503
  return MY_BIT_NONE;
506
504
}
507
505
 
508
506
 
509
 
uint bitmap_get_first(const MY_BITMAP *map)
 
507
uint32_t bitmap_get_first(const MY_BITMAP *map)
510
508
{
511
 
  uchar *byte_ptr;
512
 
  uint i,j,k;
 
509
  unsigned char *byte_ptr;
 
510
  uint32_t i,j,k;
513
511
  my_bitmap_map *data_ptr, *end= map->last_word_ptr;
514
512
 
515
 
  DBUG_ASSERT(map->bitmap);
 
513
  assert(map->bitmap);
516
514
  data_ptr= map->bitmap;
517
515
  *map->last_word_ptr|= map->last_word_mask;
518
516
 
520
518
  {
521
519
    if (*data_ptr != 0xFFFFFFFF)
522
520
    {
523
 
      byte_ptr= (uchar*)data_ptr;
 
521
      byte_ptr= (unsigned char*)data_ptr;
524
522
      for (j=0; ; j++, byte_ptr++)
525
523
      { 
526
524
        if (*byte_ptr != 0xFF)
530
528
            if (!(*byte_ptr & (1 << k)))
531
529
              return (i*32) + (j*8) + k;
532
530
          }
533
 
          DBUG_ASSERT(0);
 
531
          assert(0);
534
532
        }
535
533
      }
536
 
      DBUG_ASSERT(0);
 
534
      assert(0);
537
535
    }
538
536
  }
539
537
  return MY_BIT_NONE;
540
538
}
541
539
 
542
540
 
543
 
uint bitmap_lock_set_next(MY_BITMAP *map)
 
541
uint32_t bitmap_lock_set_next(MY_BITMAP *map)
544
542
{
545
 
  uint bit_found;
 
543
  uint32_t bit_found;
546
544
  bitmap_lock(map);
547
545
  bit_found= bitmap_set_next(map);
548
546
  bitmap_unlock(map);
550
548
}
551
549
 
552
550
 
553
 
void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit)
 
551
void bitmap_lock_clear_bit(MY_BITMAP *map, uint32_t bitmap_bit)
554
552
{
555
553
  bitmap_lock(map);
556
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
554
  assert(map->bitmap && bitmap_bit < map->n_bits);
557
555
  bitmap_clear_bit(map, bitmap_bit);
558
556
  bitmap_unlock(map);
559
557
}
560
558
 
561
559
 
562
560
#ifdef NOT_USED
563
 
bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint prefix_size)
 
561
bool bitmap_lock_is_prefix(const MY_BITMAP *map, uint32_t prefix_size)
564
562
{
565
563
  bool res;
566
564
  bitmap_lock((MY_BITMAP *)map);
586
584
}
587
585
 
588
586
 
589
 
void bitmap_lock_set_prefix(MY_BITMAP *map, uint prefix_size)
 
587
void bitmap_lock_set_prefix(MY_BITMAP *map, uint32_t prefix_size)
590
588
{
591
589
  bitmap_lock(map);
592
590
  bitmap_set_prefix(map, prefix_size);
596
594
 
597
595
bool bitmap_lock_is_clear_all(const MY_BITMAP *map)
598
596
{
599
 
  uint res;
 
597
  uint32_t res;
600
598
  bitmap_lock((MY_BITMAP *)map);
601
599
  res= bitmap_is_clear_all(map);
602
600
  bitmap_unlock((MY_BITMAP *)map);
606
604
 
607
605
bool bitmap_lock_is_set_all(const MY_BITMAP *map)
608
606
{
609
 
  uint res;
 
607
  uint32_t res;
610
608
  bitmap_lock((MY_BITMAP *)map);
611
609
  res= bitmap_is_set_all(map);
612
610
  bitmap_unlock((MY_BITMAP *)map);
614
612
}
615
613
 
616
614
 
617
 
bool bitmap_lock_is_set(const MY_BITMAP *map, uint bitmap_bit)
 
615
bool bitmap_lock_is_set(const MY_BITMAP *map, uint32_t bitmap_bit)
618
616
{
619
617
  bool res;
620
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
618
  assert(map->bitmap && bitmap_bit < map->n_bits);
621
619
  bitmap_lock((MY_BITMAP *)map);
622
620
  res= bitmap_is_set(map, bitmap_bit);
623
621
  bitmap_unlock((MY_BITMAP *)map);
627
625
 
628
626
bool bitmap_lock_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2)
629
627
{
630
 
  uint res;
 
628
  uint32_t res;
631
629
  bitmap_lock((MY_BITMAP *)map1);
632
630
  bitmap_lock((MY_BITMAP *)map2);
633
631
  res= bitmap_is_subset(map1, map2);
639
637
 
640
638
bool bitmap_lock_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
641
639
{
642
 
  uint res;
 
640
  uint32_t res;
643
641
 
644
 
  DBUG_ASSERT(map1->bitmap && map2->bitmap &&
 
642
  assert(map1->bitmap && map2->bitmap &&
645
643
              map1->n_bits==map2->n_bits);
646
644
  bitmap_lock((MY_BITMAP *)map1);
647
645
  bitmap_lock((MY_BITMAP *)map2);
689
687
  RETURN
690
688
    Number of set bits in the bitmap.
691
689
*/
692
 
uint bitmap_lock_bits_set(const MY_BITMAP *map)
 
690
uint32_t bitmap_lock_bits_set(const MY_BITMAP *map)
693
691
{
694
 
  uint res;
 
692
  uint32_t res;
695
693
  bitmap_lock((MY_BITMAP *)map);
696
 
  DBUG_ASSERT(map->bitmap);
 
694
  assert(map->bitmap);
697
695
  res= bitmap_bits_set(map);
698
696
  bitmap_unlock((MY_BITMAP *)map);
699
697
  return res;
707
705
  RETURN 
708
706
    Number of first unset bit in the bitmap or MY_BIT_NONE if all bits are set.
709
707
*/
710
 
uint bitmap_lock_get_first(const MY_BITMAP *map)
 
708
uint32_t bitmap_lock_get_first(const MY_BITMAP *map)
711
709
{
712
 
  uint res;
 
710
  uint32_t res;
713
711
  bitmap_lock((MY_BITMAP*)map);
714
712
  res= bitmap_get_first(map);
715
713
  bitmap_unlock((MY_BITMAP*)map);
717
715
}
718
716
 
719
717
 
720
 
uint bitmap_lock_get_first_set(const MY_BITMAP *map)
 
718
uint32_t bitmap_lock_get_first_set(const MY_BITMAP *map)
721
719
{
722
 
  uint res;
 
720
  uint32_t res;
723
721
  bitmap_lock((MY_BITMAP*)map);
724
722
  res= bitmap_get_first_set(map);
725
723
  bitmap_unlock((MY_BITMAP*)map);
727
725
}
728
726
 
729
727
 
730
 
void bitmap_lock_set_bit(MY_BITMAP *map, uint bitmap_bit)
 
728
void bitmap_lock_set_bit(MY_BITMAP *map, uint32_t bitmap_bit)
731
729
{
732
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
730
  assert(map->bitmap && bitmap_bit < map->n_bits);
733
731
  bitmap_lock(map);
734
732
  bitmap_set_bit(map, bitmap_bit);
735
733
  bitmap_unlock(map);
736
734
}
737
735
 
738
736
 
739
 
void bitmap_lock_flip_bit(MY_BITMAP *map, uint bitmap_bit)
 
737
void bitmap_lock_flip_bit(MY_BITMAP *map, uint32_t bitmap_bit)
740
738
{
741
 
  DBUG_ASSERT(map->bitmap && bitmap_bit < map->n_bits);
 
739
  assert(map->bitmap && bitmap_bit < map->n_bits);
742
740
  bitmap_lock(map);
743
741
  bitmap_flip_bit(map, bitmap_bit);
744
742
  bitmap_unlock(map);
746
744
#endif
747
745
#ifdef MAIN
748
746
 
749
 
uint get_rand_bit(uint bitsize)
 
747
uint32_t get_rand_bit(uint32_t bitsize)
750
748
{
751
749
  return (rand() % bitsize);
752
750
}
753
751
 
754
 
bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize)
 
752
bool test_set_get_clear_bit(MY_BITMAP *map, uint32_t bitsize)
755
753
{
756
 
  uint i, test_bit;
757
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
754
  uint32_t i, test_bit;
 
755
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
758
756
  for (i=0; i < no_loops; i++)
759
757
  {
760
758
    test_bit= get_rand_bit(bitsize);
774
772
  return true;
775
773
}
776
774
 
777
 
bool test_flip_bit(MY_BITMAP *map, uint bitsize)
 
775
bool test_flip_bit(MY_BITMAP *map, uint32_t bitsize)
778
776
{
779
 
  uint i, test_bit;
780
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
777
  uint32_t i, test_bit;
 
778
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
781
779
  for (i=0; i < no_loops; i++)
782
780
  {
783
781
    test_bit= get_rand_bit(bitsize);
798
796
}
799
797
 
800
798
bool test_operators(MY_BITMAP *map __attribute__((unused)),
801
 
                    uint bitsize __attribute__((unused)))
 
799
                    uint32_t bitsize __attribute__((unused)))
802
800
{
803
801
  return false;
804
802
}
805
803
 
806
 
bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
 
804
bool test_get_all_bits(MY_BITMAP *map, uint32_t bitsize)
807
805
{
808
 
  uint i;
 
806
  uint32_t i;
809
807
  bitmap_set_all(map);
810
808
  if (!bitmap_is_set_all(map))
811
809
    goto error1;
845
843
  return true;
846
844
}
847
845
 
848
 
bool test_compare_operators(MY_BITMAP *map, uint bitsize)
 
846
bool test_compare_operators(MY_BITMAP *map, uint32_t bitsize)
849
847
{
850
 
  uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
851
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
848
  uint32_t i, j, test_bit1, test_bit2, test_bit3,test_bit4;
 
849
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
852
850
  MY_BITMAP map2_obj, map3_obj;
853
851
  MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
854
852
  my_bitmap_map map2buf[1024];
951
949
  return true;
952
950
}
953
951
 
954
 
bool test_count_bits_set(MY_BITMAP *map, uint bitsize)
 
952
bool test_count_bits_set(MY_BITMAP *map, uint32_t bitsize)
955
953
{
956
 
  uint i, bit_count=0, test_bit;
957
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
954
  uint32_t i, bit_count=0, test_bit;
 
955
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
958
956
  for (i=0; i < no_loops; i++)
959
957
  {
960
958
    test_bit=get_rand_bit(bitsize);
977
975
  return true;
978
976
}
979
977
 
980
 
bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
 
978
bool test_get_first_bit(MY_BITMAP *map, uint32_t bitsize)
981
979
{
982
 
  uint i, test_bit;
983
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
980
  uint32_t i, test_bit;
 
981
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
984
982
  for (i=0; i < no_loops; i++)
985
983
  {
986
984
    test_bit=get_rand_bit(bitsize);
1002
1000
  return true;
1003
1001
}
1004
1002
 
1005
 
bool test_get_next_bit(MY_BITMAP *map, uint bitsize)
 
1003
bool test_get_next_bit(MY_BITMAP *map, uint32_t bitsize)
1006
1004
{
1007
 
  uint i, j, test_bit;
1008
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
1005
  uint32_t i, j, test_bit;
 
1006
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
1009
1007
  for (i=0; i < no_loops; i++)
1010
1008
  {
1011
1009
    test_bit=get_rand_bit(bitsize);
1021
1019
  return true;
1022
1020
}
1023
1021
 
1024
 
bool test_prefix(MY_BITMAP *map, uint bitsize)
 
1022
bool test_prefix(MY_BITMAP *map, uint32_t bitsize)
1025
1023
{
1026
 
  uint i, j, test_bit;
1027
 
  uint no_loops= bitsize > 128 ? 128 : bitsize;
 
1024
  uint32_t i, j, test_bit;
 
1025
  uint32_t no_loops= bitsize > 128 ? 128 : bitsize;
1028
1026
  for (i=0; i < no_loops; i++)
1029
1027
  {
1030
1028
    test_bit=get_rand_bit(bitsize);
1056
1054
}
1057
1055
 
1058
1056
 
1059
 
bool do_test(uint bitsize)
 
1057
bool do_test(uint32_t bitsize)
1060
1058
{
1061
1059
  MY_BITMAP map;
1062
1060
  my_bitmap_map buf[1024];