-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmextra.hpp
More file actions
93 lines (84 loc) · 2.8 KB
/
fmextra.hpp
File metadata and controls
93 lines (84 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 the "License"; you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
Portions created by the Initial Developer are Copyright (c) 2022
the Initial Developer. All Rights Reserved.
*/
#ifndef __flmgr_included
#error [flmgr] PREPROCESSOR SYSTEM @ Error: This file is not standalone.
#endif
namespace flmgr
{
namespace mem_const
{
const int intbits = sizeof(int)*8;
}
namespace extra
{
template<const unsigned int t_bitarraysize> class bitarray
{
private:
int bitarraysize = t_bitarraysize;
int bitarrayvalue[(t_bitarraysize/(flmgr::mem_const::intbits))+1];
public:
bitarray()
{
std::cout << "Created a bitarray with a size of " << sizeof(bitarrayvalue)/sizeof(int) << std::endl;
if(!(0 < this->bitarraysize))
{
this->bitarraysize = 32;
}
for(int i = 0; i < sizeof(bitarrayvalue)/sizeof(int); i++)
{
bitarrayvalue[i] = 0;
}
}
int get_size()
{
return this->bitarraysize;
}
void clear()
{
for(int i; i < sizeof(bitarrayvalue); i++)
{
bitarrayvalue[i] = 0;
}
}
int get_at(int index)
{
if(index >= this->bitarraysize)
{
throw (index);
return 0;
}
return (bitarrayvalue[index/(flmgr::mem_const::intbits)]) & (1 << (index % (flmgr::mem_const::intbits))) ? 1 : 0;
}
int set_at(int index, int value)
{
if(value != 0 && value != 1)
{
throw (value);
return 1;
}
if(!(0 <= index < this->bitarraysize))
{
throw(index);
return 1;
}
int arridx = index/(flmgr::mem_const::intbits);
int bitidx = index % (flmgr::mem_const::intbits);
bitarrayvalue[arridx] = value ?
bitarrayvalue[arridx] | (1 << bitidx) :
bitarrayvalue[arridx] & ~(1 << bitidx);
return 0;
}
};
}
}