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
188db687
Commit
188db687
authored
Mar 19, 2024
by
Nikita Malyavin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix integer types
parent
4a4fe078
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
22 deletions
+25
-22
include/open_address_hash.h
include/open_address_hash.h
+25
-22
No files found.
include/open_address_hash.h
View file @
188db687
...
...
@@ -49,7 +49,7 @@ class Open_address_hash
private:
Hash_value_type
to_index
(
const
Hash_value_type
&
hash_value
)
const
{
return
hash_value
&
((
1
<<
capacity_power
)
-
1
);
return
hash_value
&
((
1
UL
<<
capacity_power
)
-
1
);
}
Hash_value_type
hash_from_value
(
const
Value
&
value
)
const
...
...
@@ -102,11 +102,11 @@ class Open_address_hash
return
false
;
}
bool
grow
(
const
uint
64
new_capacity_power
)
bool
grow
(
const
uint
new_capacity_power
)
{
DBUG_ASSERT
(
new_capacity_power
>
capacity_power
);
uint64
past_capacity
=
1
<<
capacity_power
;
uint64
capacity
=
1
<<
new_capacity_power
;
size_t
past_capacity
=
1UL
<<
capacity_power
;
size_t
capacity
=
1UL
<<
new_capacity_power
;
capacity_power
=
new_capacity_power
;
hash_array
=
(
Value
*
)
realloc
(
hash_array
,
capacity
*
sizeof
(
Value
));
if
(
!
hash_array
)
...
...
@@ -114,7 +114,7 @@ class Open_address_hash
bzero
(
hash_array
+
past_capacity
,
(
capacity
-
past_capacity
)
*
sizeof
(
Value
*
));
for
(
uin
t
i
=
0
;
i
<
capacity
;
i
++
)
for
(
size_
t
i
=
0
;
i
<
capacity
;
i
++
)
{
if
(
hash_array
[
i
]
&&
i
!=
to_index
(
hash_from_value
(
hash_array
[
i
])))
{
...
...
@@ -126,14 +126,14 @@ class Open_address_hash
return
true
;
}
void
shrink
(
const
uint
64
new_capacity_power
)
void
shrink
(
const
uint
new_capacity_power
)
{
DBUG_ASSERT
(
new_capacity_power
<
capacity_power
);
uint64
past_capacity
=
1
<<
capacity_power
;
uint64
capacity
=
1
<<
new_capacity_power
;
size_t
past_capacity
=
1UL
<<
capacity_power
;
size_t
capacity
=
1UL
<<
new_capacity_power
;
capacity_power
=
new_capacity_power
;
for
(
uin
t
i
=
capacity
;
i
<
past_capacity
;
i
++
)
for
(
size_
t
i
=
capacity
;
i
<
past_capacity
;
i
++
)
{
if
(
hash_array
[
i
])
{
...
...
@@ -152,7 +152,7 @@ class Open_address_hash
Value
_second
=
second
;
capacity_power
=
CAPACITY_POWER_INITIAL
;
hash_array
=
(
Value
*
)
calloc
(
1
<<
capacity_power
,
sizeof
(
Value
*
));
hash_array
=
(
Value
*
)
calloc
(
1
UL
<<
capacity_power
,
sizeof
(
Value
*
));
_size
=
0
;
if
(
!
insert_into_bucket
(
_first
))
...
...
@@ -212,7 +212,7 @@ class Open_address_hash
return
false
;
}
const
uint64_t
capacity
=
1
<<
capacity_power
;
const
size_t
capacity
=
1UL
<<
capacity_power
;
if
(
unlikely
(
capacity
>
7
&&
(
_size
-
1
)
*
LOW_LOAD_FACTOR
<
capacity
))
shrink
(
capacity_power
-
1
);
...
...
@@ -248,12 +248,12 @@ class Open_address_hash
}
}
if
(
unlikely
(
_size
==
UINT32
_MAX
))
if
(
unlikely
(
_size
==
TABLE_SIZE
_MAX
))
return
false
;
bool
res
=
true
;
const
uint64
capacity
=
1
<<
capacity_power
;
if
(
unlikely
((
_size
+
1
)
*
MAX_LOAD_FACTOR
>
capacity
))
const
size_t
capacity
=
1UL
<<
capacity_power
;
if
(
unlikely
((
(
ulonglong
)
_size
+
1
)
*
MAX_LOAD_FACTOR
>
capacity
))
res
=
grow
(
capacity_power
+
1
);
res
=
res
&&
insert_into_bucket
(
value
);
...
...
@@ -283,11 +283,11 @@ class Open_address_hash
return
true
;
}
uint32
size
()
const
size_t
size
()
const
{
if
(
first
.
mark
())
{
uint32
ret_size
=
0
;
size_t
ret_size
=
0
;
if
(
!
is_empty
(
first
.
ptr
()))
ret_size
++
;
if
(
!
is_empty
(
second
))
...
...
@@ -299,7 +299,8 @@ class Open_address_hash
return
_size
;
}
}
uint32
buffer_size
()
const
{
return
first
.
mark
()
?
0
:
1
<<
capacity_power
;
}
size_t
buffer_size
()
const
{
return
first
.
mark
()
?
0
:
1UL
<<
capacity_power
;
}
Open_address_hash
&
operator
=
(
const
Open_address_hash
&
)
{
...
...
@@ -308,14 +309,16 @@ class Open_address_hash
}
private:
static
constexpr
uint
CAPACITY_POWER_INITIAL
=
3
;
static
constexpr
int
MAX_LOAD_FACTOR
=
2
;
static
constexpr
int
LOW_LOAD_FACTOR
=
10
;
static
constexpr
ulong
MAX_LOAD_FACTOR
=
2
;
static
constexpr
ulong
LOW_LOAD_FACTOR
=
10
;
static
constexpr
size_t
SIZE_BITS
=
SIZEOF_VOIDP
>=
8
?
58
:
32
;
static
constexpr
size_t
TABLE_SIZE_MAX
=
1L
<<
SIZE_BITS
;
class
markable_reference
{
public:
static
constexpr
uint
MARK_SHIFT
=
63
;
static
constexpr
uintptr_t
MARK_MASK
=
1UL
L
<<
MARK_SHIFT
;
static
constexpr
uintptr_t
MARK_MASK
=
1UL
<<
MARK_SHIFT
;
void
set_ptr
(
Value
ptr
)
{
...
...
@@ -352,8 +355,8 @@ class Open_address_hash
struct
{
Value
*
hash_array
;
uint
64
capacity_power
:
6
;
uint64
_size
:
58
;
uint
capacity_power
:
6
;
size_t
_size
:
SIZE_BITS
;
};
}
;
}
;
...
...
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