QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
bitarray.h
Go to the documentation of this file.
1 /*
2  * QuickRank - A C++ suite of Learning to Rank algorithms
3  * Webpage: http://quickrank.isti.cnr.it/
4  * Contact: quickrank@isti.cnr.it
5  *
6  * Unless explicitly acquired and licensed from Licensor under another
7  * license, the contents of this file are subject to the Reciprocal Public
8  * License ("RPL") Version 1.5, or subsequent versions as allowed by the RPL,
9  * and You may not copy or use this file in either source code or executable
10  * form, except in compliance with the terms and conditions of the RPL.
11  *
12  * All software distributed under the RPL is provided strictly on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND
14  * LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
15  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16  * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific
17  * language governing rights and limitations under the RPL.
18  *
19  * Contributor:
20  * HPC. Laboratory - ISTI - CNR - http://hpc.isti.cnr.it/
21  */
22 #pragma once
23 
24 #include <cstdlib>
25 #include <cstdint>
26 
27 /*! \class bitarray
28  * \brief bit array implementation (1 bit per element)
29  */
30 class BitArray {
31  public:
32  /** \brief default constructor
33  */
35  : data(NULL),
36  datasize(0) {
37  }
39  free(data);
40  }
41  /** \brief set the \a i-th bit (the data structure is reallocated to store the \a i-th bit if needed)
42  */
43  void set_up(const size_t i);
44 
45  /** \brief return true the \a i-th bit is set (no check is made on the size of the array)
46  */
47  bool is_up(const size_t i) const;
48  /** \brief return the number of set bit in the array
49  */
50  size_t get_upcounter();
51 
52  /** \brief return an array of integers made up of the set bits positions
53  */
54  size_t *get_uparray(const size_t n);
55 
56  /** \brief compute bitwse OR of two bit arrays and store the result in the left operand
57  */
58  BitArray &operator|=(const BitArray &other);
59 
60  private:
61  int32_t *data;
62  size_t datasize;
63 };
size_t * get_uparray(const size_t n)
return an array of integers made up of the set bits positions
Definition: bitarray.cc:76
int32_t * data
Definition: bitarray.h:61
void set_up(const size_t i)
set the i-th bit (the data structure is reallocated to store the i-th bit if needed) ...
Definition: bitarray.cc:52
BitArray()
default constructor
Definition: bitarray.h:34
size_t datasize
Definition: bitarray.h:62
Definition: bitarray.h:30
~BitArray()
Definition: bitarray.h:38
bool is_up(const size_t i) const
return true the i-th bit is set (no check is made on the size of the array)
Definition: bitarray.cc:63
BitArray & operator|=(const BitArray &other)
compute bitwse OR of two bit arrays and store the result in the left operand
Definition: bitarray.cc:86
size_t get_upcounter()
return the number of set bit in the array
Definition: bitarray.cc:68