Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
58582d73
Commit
58582d73
authored
Jun 03, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More testcode for shortcode.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
3c314c27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
testshortcode.cc
src/testshortcode.cc
+93
-0
No files found.
src/testshortcode.cc
View file @
58582d73
...
...
@@ -16,6 +16,8 @@
*/
#include <vector>
#include <map>
#include <sstream>
#include <sys/time.h>
#include <assert.h>
...
...
@@ -24,6 +26,7 @@
using
std
::
vector
;
using
std
::
string
;
using
std
::
map
;
static
double
gettime
()
...
...
@@ -34,6 +37,50 @@ gettime()
return
tv
.
tv_sec
+
tv
.
tv_usec
/
1000000.0
;
}
vector
<
int
>
generate_error_vector
(
size_t
n
,
int
errors
)
{
vector
<
int
>
ev
(
n
);
while
(
errors
)
{
size_t
pos
=
rand
()
%
ev
.
size
();
if
(
ev
[
pos
]
!=
1
)
{
ev
[
pos
]
=
1
;
errors
--
;
}
}
return
ev
;
}
int
hamming_weight
(
const
vector
<
int
>&
bits
)
{
int
w
=
0
;
for
(
auto
b
:
bits
)
w
+=
b
;
return
w
;
}
double
factorial
(
int
x
)
{
double
p
=
1
;
for
(
int
i
=
1
;
i
<=
x
;
i
++
)
p
*=
i
;
return
p
;
}
string
number_format
(
double
d
)
{
std
::
ostringstream
buff
;
buff
.
imbue
(
std
::
locale
(
""
));
buff
<<
(
uint64_t
)
d
;
return
buff
.
str
();
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -73,4 +120,50 @@ main (int argc, char **argv)
}
printf
(
"%.1f ms/block
\n
"
,
(
gettime
()
-
start_t
)
/
runs
*
1000.0
);
}
if
(
argc
==
2
&&
string
(
argv
[
1
])
==
"table"
)
{
map
<
vector
<
int
>
,
vector
<
int
>>
table
;
vector
<
int
>
weight
(
48
+
1
);
for
(
size_t
i
=
0
;
i
<
(
1
<<
16
);
i
++
)
{
vector
<
int
>
in
;
for
(
size_t
bit
=
0
;
bit
<
16
;
bit
++
)
{
if
(
i
&
(
1
<<
bit
))
in
.
push_back
(
1
);
else
in
.
push_back
(
0
);
}
vector
<
int
>
coded_bits
=
short_encode_blk
(
in
);
table
[
coded_bits
]
=
in
;
weight
[
hamming_weight
(
coded_bits
)]
++
;
printf
(
"T: "
);
for
(
auto
b
:
coded_bits
)
printf
(
"%d"
,
b
);
printf
(
"
\n
"
);
}
for
(
size_t
i
=
0
;
i
<=
48
;
i
++
)
{
if
(
weight
[
i
])
printf
(
"W %3zd %6d %20s
\n
"
,
i
,
weight
[
i
],
number_format
(
factorial
(
48
)
/
(
factorial
(
i
)
*
factorial
(
48
-
i
))
/
weight
[
i
]).
c_str
());
}
const
size_t
runs
=
50LL
*
1000
*
1000
*
1000
;
size_t
match
=
0
;
for
(
size_t
i
=
0
;
i
<
runs
;
i
++
)
{
vector
<
int
>
in_bits
=
generate_error_vector
(
48
,
16
);
auto
it
=
table
.
find
(
in_bits
);
if
(
it
!=
table
.
end
())
match
++
;
if
((
i
%
1000000
)
==
0
)
{
printf
(
"%zd / %zd
\r
"
,
match
,
i
);
fflush
(
stdout
);
}
}
}
}
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