Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
nanahira
Stunserver
Commits
7b1d6795
Commit
7b1d6795
authored
Jan 19, 2012
by
John Selbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick fix
parent
7f0b7471
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
2 deletions
+54
-2
common/fasthash.cpp
common/fasthash.cpp
+52
-0
common/fasthash.h
common/fasthash.h
+2
-2
No files found.
common/fasthash.cpp
0 → 100644
View file @
7b1d6795
#include "commonincludes.h"
#define IS_DIVISIBLE_BY(x, y) ((x % y)==0)
static
unsigned
int
FindPrime
(
unsigned
int
val
)
{
unsigned
int
result
=
val
;
bool
fPrime
=
false
;
if
(
val
<=
2
)
{
return
2
;
}
if
(
val
==
3
)
{
return
3
;
}
if
((
result
%
2
)
==
0
)
{
result
++
;
}
while
(
fPrime
==
false
)
{
unsigned
int
stop
=
(
unsigned
int
)(
sqrt
(
result
)
+
1
);
fPrime
=
true
;
// test to see if result is prime, if it is, return it
for
(
unsigned
int
x
=
3
;
x
<=
stop
;
x
++
)
{
if
(
IS_DIVISIBLE_BY
(
result
,
x
))
{
fPrime
=
false
;
break
;
}
}
if
(
fPrime
==
false
)
{
result
+=
2
;
}
}
return
result
;
}
size_t
FastHash_GetHashTableWidth
(
unsigned
int
maxConnections
)
{
// find highest prime, greater than or equal to maxConnections
return
FindPrime
(
maxConnections
);
}
common/fasthash.h
View file @
7b1d6795
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
// Use FastHash when the maximum number of elements in the hash table is known at compile time
// Use FastHash when the maximum number of elements in the hash table is known at compile time
size_t
FastHash_GetHashTableWidth
(
unsigned
int
max
Connection
s
);
size_t
FastHash_GetHashTableWidth
(
unsigned
int
max
Item
s
);
inline
size_t
FastHash_Hash
(
void
*
ptr
)
inline
size_t
FastHash_Hash
(
void
*
ptr
)
...
...
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