Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
e39f328e
Commit
e39f328e
authored
May 05, 2005
by
mronstrom@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
After test on Mac OS X fixes
parent
abec3ade
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
18 deletions
+54
-18
sql/bitvector.cc
sql/bitvector.cc
+37
-11
sql/bitvector.h
sql/bitvector.h
+17
-7
No files found.
sql/bitvector.cc
View file @
e39f328e
...
@@ -29,7 +29,8 @@ void bitvector::create_last_word_mask()
...
@@ -29,7 +29,8 @@ void bitvector::create_last_word_mask()
* bits clear. The bits within each byte is stored in big-endian order.
* bits clear. The bits within each byte is stored in big-endian order.
*/
*/
unsigned
char
const
mask
=
(
~
((
1
<<
used
)
-
1
))
&
255
;
unsigned
char
const
mask
=
(
~
((
1
<<
used
)
-
1
))
&
255
;
last_word_ptr
=
(
uint32
*
)(
m_data
+
((
bytes
()
-
1U
)
>>
2
));
unsigned
int
byte_no
=
((
bytes
()
-
1
))
&
~
3U
;
last_word_ptr
=
(
uint32
*
)
&
m_data
[
byte_no
];
/*
/*
The first bytes are to be set to zero since they represent real bits
The first bytes are to be set to zero since they represent real bits
...
@@ -65,6 +66,7 @@ void bitvector::create_last_word_mask()
...
@@ -65,6 +66,7 @@ void bitvector::create_last_word_mask()
int
bitvector
::
init
(
size_t
size
)
int
bitvector
::
init
(
size_t
size
)
{
{
DBUG_ASSERT
(
size
<
MYSQL_NO_BIT_FOUND
);
DBUG_ASSERT
(
size
<
MYSQL_NO_BIT_FOUND
);
DBUG_ASSERT
(
size
>
0
);
m_size
=
size
;
m_size
=
size
;
m_data
=
(
uchar
*
)
my_malloc
(
byte_size_word_aligned
(
size
),
MYF
(
0
));
m_data
=
(
uchar
*
)
my_malloc
(
byte_size_word_aligned
(
size
),
MYF
(
0
));
if
(
m_data
)
if
(
m_data
)
...
@@ -289,32 +291,56 @@ bool do_test(uint bitsize)
...
@@ -289,32 +291,56 @@ bool do_test(uint bitsize)
bv
=
new
bitvector
;
bv
=
new
bitvector
;
bv
->
init
(
bitsize
);
bv
->
init
(
bitsize
);
if
(
test_set_get_clear_bit
(
bv
,
bitsize
))
if
(
test_set_get_clear_bit
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_flip_bit
(
bv
,
bitsize
))
if
(
test_flip_bit
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_operators
(
bv
,
bitsize
))
if
(
test_operators
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_get_all_bits
(
bv
,
bitsize
))
if
(
test_get_all_bits
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_compare_operators
(
bv
,
bitsize
))
if
(
test_compare_operators
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_count_bits_set
(
bv
,
bitsize
))
if
(
test_count_bits_set
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_get_first_bit
(
bv
,
bitsize
))
if
(
test_get_first_bit
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
bv
->
clear_all
();
if
(
test_get_next_bit
(
bv
,
bitsize
))
if
(
test_get_next_bit
(
bv
,
bitsize
))
return
TRUE
;
goto
error
;
printf
(
"OK"
)
;
delete
bv
;
return
FALSE
;
return
FALSE
;
error:
delete
bv
;
printf
(
"
\n
"
);
return
TRUE
;
}
}
int
main
()
int
main
()
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
4096
;
i
++
)
for
(
i
=
1
;
i
<
4096
;
i
++
)
if
(
do_test
(
i
))
if
(
do_test
(
i
))
return
-
1
;
return
-
1
;
printf
(
"OK
\n
"
);
return
0
;
return
0
;
}
}
/*
Compile by using the below on a compiled clone
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../include -I../regex -I. -I../include
-g -fno-omit-frame-pointer -fno-common -felide-constructors -fno-exceptions
-fno-rtti -fno-implicit-templates -fno-exceptions -fno-rtti
-DUSE_MYSYS_NEW -DDEFINE_CXA_PURE_VIRTUAL -DHAVE_DARWIN_THREADS
-D_P1003_1B_VISIBLE -DTEST_BITVECTOR -DSIGNAL_WITH_VIO_CLOSE
-DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -o bitvector.o
-c bitvector.cc
g++ -o bitvector bitvector.o -L../mysys -lmysys -L../dbug -L../strings
-lmystrings -ldbug
*/
#endif
#endif
sql/bitvector.h
View file @
e39f328e
...
@@ -177,8 +177,8 @@ class bitvector
...
@@ -177,8 +177,8 @@ class bitvector
bool
get_all_bits_clear
()
bool
get_all_bits_clear
()
{
{
uint32
*
data_ptr
=
(
uint32
*
)
&
m_data
[
0
]
;
uint32
*
data_ptr
=
(
uint32
*
)
m_data
;
if
(
*
last_word_ptr
^
last_word_mask
)
if
(
*
last_word_ptr
!=
last_word_mask
)
return
FALSE
;
return
FALSE
;
for
(;
data_ptr
<
last_word_ptr
;
data_ptr
++
)
for
(;
data_ptr
<
last_word_ptr
;
data_ptr
++
)
if
(
*
data_ptr
)
if
(
*
data_ptr
)
...
@@ -204,7 +204,8 @@ class bitvector
...
@@ -204,7 +204,8 @@ class bitvector
/* Set a bit to a value */
/* Set a bit to a value */
void
set_bit
(
size_t
pos
)
void
set_bit
(
size_t
pos
)
{
{
*
(
uchar
*
)(
m_data
+
(
pos
>>
3
))
|=
(
uchar
)(
1
<<
(
pos
&
0x7U
));
DBUG_ASSERT
(
pos
<
m_size
);
m_data
[
pos
>>
3
]
|=
(
uchar
)(
1
<<
(
pos
&
0x7U
));
}
}
/* Reset (clear) all bits in the vector */
/* Reset (clear) all bits in the vector */
...
@@ -217,18 +218,27 @@ class bitvector
...
@@ -217,18 +218,27 @@ class bitvector
/* Reset one bit in the vector */
/* Reset one bit in the vector */
void
clear_bit
(
size_t
pos
)
void
clear_bit
(
size_t
pos
)
{
{
*
(
u_char
*
)(
m_data
+
(
pos
>>
3
))
&=
(
u_char
)(
~
(
1
<<
(
pos
&
0x7U
)));
DBUG_ASSERT
(
pos
<
m_size
);
m_data
[
pos
>>
3
]
&=
~
(
uchar
)(
1
<<
(
pos
&
0x7U
));
}
}
void
flip_bit
(
size_t
pos
)
void
flip_bit
(
size_t
pos
)
{
{
*
(
uchar
*
)(
m_data
+
(
pos
>>
3
))
^=
(
uchar
)(
1
<<
(
pos
&
0x7U
));
DBUG_ASSERT
(
pos
<
m_size
);
m_data
[
pos
>>
3
]
^=
(
uchar
)(
1
<<
(
pos
&
0x7U
));
}
}
bool
get_bit
(
size_t
pos
)
const
bool
get_bit
(
size_t
pos
)
const
{
{
return
(
bool
)(
*
(
uchar
*
)(
m_data
+
(
pos
>>
3
)))
&
DBUG_ASSERT
(
pos
<
m_size
);
(
uchar
)(
1
<<
(
pos
&
0x7U
));
/*
!! provides the most effective implementation of conversion to
bool
*/
uchar
*
byte_word
=
m_data
+
(
pos
>>
3
);
uchar
mask
=
1
<<
(
pos
&
0x7U
);
bool
ret_value
=
!!
(
*
byte_word
&
mask
);
return
ret_value
;
};
};
bool
operator
==
(
bitvector
const
&
rhs
)
const
bool
operator
==
(
bitvector
const
&
rhs
)
const
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment