Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dubský Jan
asgn
Commits
b8f2bba6
Commit
b8f2bba6
authored
May 19, 2020
by
Dubský Jan
Browse files
Solution 4.02 (Speed: 21.77)
parent
0c003a0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
sol/matrixsol.hpp
View file @
b8f2bba6
...
...
@@ -18,8 +18,9 @@ public:
using
matrix_element
=
std
::
uint16_t
;
matrix
(
std
::
size_t
vs
,
std
::
size_t
hs
)
:
VS
(
vs
),
HS
(
hs
),
ROW_BYTES
(
calc_row_bytes
(
vs
,
hs
)),
ROW_SIZE
(
ROW_BYTES
/
sizeof
(
matrix_element
))
{
mat
=
(
uint16_t
*
)
std
::
aligned_alloc
(
CACHE_LINE_SIZE
,
VS
*
ROW_BYTES
);
VS
(
vs
),
HS
(
hs
),
ROW_BYTES
(
calc_row_bytes
(
hs
)),
COL_BYTES
(
calc_row_bytes
(
vs
)),
ROW_SIZE
(
ROW_BYTES
/
sizeof
(
matrix_element
)),
COL_SIZE
(
COL_BYTES
/
sizeof
(
matrix_element
))
{
mat
=
(
uint16_t
*
)
std
::
aligned_alloc
(
CACHE_LINE_SIZE
,
VS
*
ROW_BYTES
);
mat_r
=
(
uint16_t
*
)
std
::
aligned_alloc
(
CACHE_LINE_SIZE
,
HS
*
COL_BYTES
);
}
std
::
size_t
vsize
()
const
{
...
...
@@ -31,10 +32,12 @@ public:
}
void
set
(
std
::
size_t
i
,
std
::
size_t
j
,
matrix_element
e
)
{
addr
(
i
,
j
)
=
e
;
addr
(
i
,
j
)
=
e
;
addr_r
(
i
,
j
)
=
e
;
}
matrix_element
get
(
std
::
size_t
i
,
std
::
size_t
j
)
const
{
assert
(
addr_r
(
i
,
j
)
==
addr
(
i
,
j
));
return
addr
(
i
,
j
);
}
...
...
@@ -47,18 +50,20 @@ public:
for
(
size_t
j
=
0
;
j
<
HS
;
++
j
)
{
matrix_element
res
=
std
::
numeric_limits
<
matrix_element
>::
max
();
for
(
size_t
k
=
0
;
k
<
a
.
HS
;
++
k
)
{
res
=
std
::
min
(
res
,
(
matrix_element
)(
a
.
get
(
i
,
k
)
+
b
.
get
(
k
,
j
)));
res
=
std
::
min
(
res
,
(
matrix_element
)(
a
.
addr
(
i
,
k
)
+
b
.
addr_r
(
k
,
j
)));
}
set
(
i
,
j
,
res
);
addr
(
i
,
j
)
=
res
;
addr_r
(
i
,
j
)
=
res
;
}
}
}
private:
const
size_t
VS
,
HS
;
const
size_t
ROW_BYTES
;
const
size_t
ROW_SIZE
;
const
size_t
ROW_BYTES
,
COL_BYTES
;
const
size_t
ROW_SIZE
,
COL_SIZE
;
uint16_t
*
mat
;
uint16_t
*
mat_r
;
matrix_element
&
addr
(
size_t
row
,
size_t
col
)
const
{
assert
(
col
<
HS
);
...
...
@@ -66,8 +71,14 @@ private:
return
*
(
mat
+
(
row
*
ROW_SIZE
)
+
col
);
}
static
size_t
calc_row_bytes
(
size_t
vs
,
size_t
hs
)
{
size_t
ret
=
sizeof
(
matrix_element
)
*
hs
;
matrix_element
&
addr_r
(
size_t
row
,
size_t
col
)
const
{
assert
(
col
<
HS
);
assert
(
row
<
VS
);
return
*
(
mat_r
+
(
col
*
COL_SIZE
)
+
row
);
}
static
size_t
calc_row_bytes
(
size_t
val
)
{
size_t
ret
=
sizeof
(
matrix_element
)
*
val
;
if
(
ret
%
CACHE_LINE_SIZE
)
{
ret
+=
CACHE_LINE_SIZE
;
ret
=
(
ret
/
CACHE_LINE_SIZE
)
*
CACHE_LINE_SIZE
;
...
...
Write
Preview
Supports
Markdown
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