Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
ParaEncode
Project
Project
Details
Activity
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ParaEncode
Commits
945aac1a
Commit
945aac1a
authored
Apr 22, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CpySchedule.
parent
ee63ae87
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
14 deletions
+35
-14
encGroup.js
src/encGroup.js
+35
-14
No files found.
src/encGroup.js
View file @
945aac1a
...
...
@@ -22,19 +22,32 @@ function makeMessage(msgType, datas) {
return
{
type
:
msgType
,
data
:
datas
};
}
class
CpySchedule
{
first
=
{
pos
:
0
,
size
:
0
}
second
=
{
pos
:
0
,
size
:
0
}
}
/* An abstraction that help to
* easily to transfer datas to target worker
* in real time manner */
export
class
Channel
{
/*
| ReadPointer (4 bytes) | WritePointer (4 Bytes) | Data Area (1-n bytes)
*/
/* */
/* Size of memory area that help to
* maintain Channel. Types of meta info
* are shown below:
*
* 1.Write Position
* 2.Read Position */
* 2.Read Position
*
* Figure:
* ------------------------------------------------------------------------
* | ReadPointer (4 bytes) | WritePointer (4 Bytes) | Data Area (N bytes) |
* -------------------------------------------------------------------------
* where N >= 2
*
* */
#
numOfMetaField
=
2
#
fieldSize
=
0
;
...
...
@@ -54,6 +67,9 @@ export class Channel {
// size's unit is byte
// bufferType parameter is mainly for testability.
constructor
(
WW
,
size
,
bufferType
=
SharedArrayBuffer
)
{
assert
(
size
>=
2
,
`Channel require its data area has at least 2 Bytes.`
)
this
.
#
WW
=
WW
;
this
.
#
size
=
size
;
...
...
@@ -70,6 +86,8 @@ export class Channel {
this
.
#
view
.
setUint32
(
0
,
this
.
#
metaSize
);
this
.
#
view
.
setUint32
(
4
,
this
.
#
metaSize
);
// FIXME: Need to transfer channel itself to worker.
}
#
readPos
()
{
...
...
@@ -104,20 +122,21 @@ export class Channel {
* make sure there has enough spaces.*/
#
cpySchedule
(
size
)
{
let
firstCpySize
=
0
,
secondCpySize
=
0
,
spaceToTail
=
0
;
let
schedule
;
let
schedule
=
new
CpySchedule
()
;
if
(
this
.
#
writePos
>=
this
.
#
readPos
())
{
spaceToTail
=
this
.
#
endPos
-
this
.
#
writePos
;
firstCpySize
=
Math
.
min
(
size
,
spaceToTail
);
secondCpySize
=
firstCpySize
<
size
?
size
-
firstCpySize
:
0
;
schedule
=
{
first
:
{
pos
:
this
.
#
writePos
,
size
:
firstCpySize
},
second
:
{
pos
:
secondCpySize
>
0
?
this
.
#
metaSize
:
0
,
size
:
secondCpySize
}
};
schedule
.
first
.
pos
=
this
.
#
writePos
;
schedule
.
first
.
size
=
firstCpySize
;
schedule
.
second
.
pos
=
secondCpySize
>
0
?
this
.
#
metaSize
:
0
;
schedule
.
second
.
size
=
secondCpySize
;
}
else
{
schedule
=
{
first
:
{
pos
:
this
.
#
writePos
,
size
:
firstCpySize
},
second
:
{
pos
:
0
,
size
:
0
}
}
;
schedule
.
first
.
pos
=
this
.
#
writePos
;
schedule
.
first
.
size
=
firstCpySize
;
}
return
schedule
;
...
...
@@ -182,15 +201,17 @@ export class Channel {
let
schedule
=
this
.
#
cpySchedule
(
data
.
byteLength
);
// Perfrom write schedule
let
srcPos
=
0
;
let
srcPos
=
0
,
plan
;
for
(
let
key
in
schedule
)
{
let
plan
=
schedule
[
key
];
plan
=
schedule
[
key
];
if
(
plan
.
size
==
0
)
continue
;
let
d_
=
data
.
slice
(
srcPos
,
srcPos
+
plan
.
size
);
this
.
#
buffer
.
set
(
d_
,
plan
.
pos
)
srcPos
=
srcPos
+
plan
.
size
;
this
.
#
buffer
.
set
(
data
.
slice
(
srcPos
,
srcPos
+
plan
.
size
)
,
plan
.
pos
)
srcPos
+=
plan
.
size
;
writePos
=
plan
.
pos
+
plan
.
size
;
}
...
...
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