~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_bitmap.cc

Merged Padraig.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *
 
6
 *  Authors:
 
7
 *
 
8
 *  Padraig O'Sullivan <osullivan.padraig@gmail.com>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
23
 */
 
24
 
 
25
/**
 
26
 * @file 
 
27
 *
 
28
 * Implementation of helper methods for working with
 
29
 * bitsets and methods for thread-safe bitsets.
 
30
 */
 
31
 
 
32
#include "drizzled/sql_bitmap.h"
 
33
 
 
34
#include <bitset>
 
35
 
 
36
using namespace std;
 
37
 
 
38
void ThreadSafeBitset::resetBit(uint32_t pos)
 
39
{
 
40
  pthread_mutex_lock(&mutex);
 
41
  bitmap.reset(pos);
 
42
  pthread_mutex_unlock(&mutex);
 
43
}
 
44
 
 
45
uint32_t ThreadSafeBitset::setNextBit()
 
46
{
 
47
  uint32_t bit_found;
 
48
  pthread_mutex_lock(&mutex);
 
49
  if ((bit_found= getFirstBitPos(bitmap)) != MY_BIT_NONE)
 
50
    bitmap.set(bit_found);
 
51
  pthread_mutex_unlock(&mutex);
 
52
  return bit_found;
 
53
}
 
54
 
 
55
uint32_t getFirstBitPos(const bitset<MAX_FIELDS> &bitmap)
 
56
{
 
57
  uint32_t first_bit= MY_BIT_NONE;
 
58
  for (int idx= 0; idx < MAX_FIELDS; idx++)
 
59
  {
 
60
    if (!bitmap.test(idx))
 
61
    {
 
62
      first_bit= idx;
 
63
      break;
 
64
    }
 
65
  }
 
66
  return first_bit;
 
67
}
 
68
 
 
69
bool isBitmapSubset(const bitset<MAX_FIELDS> *map1, const bitset<MAX_FIELDS> *map2)
 
70
{
 
71
  bitset<MAX_FIELDS> tmp1= *map2;
 
72
  bitset<MAX_FIELDS> tmp2= *map1 & tmp1.flip();
 
73
  return (!tmp2.any());
 
74
}
 
75
 
 
76
bool isBitmapOverlapping(const bitset<MAX_FIELDS> *map1, const bitset<MAX_FIELDS> *map2)
 
77
{
 
78
  bitset<MAX_FIELDS> tmp= *map1 & *map2;
 
79
  return (tmp.any());
 
80
}