Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
yjs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
yjs
Commits
8f63147d
Commit
8f63147d
authored
9 years ago
by
Kevin Jahns
Browse files
Options
Downloads
Patches
Plain Diff
added Map struct
parent
7a274565
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Struct.js
+79
-52
79 additions, 52 deletions
src/Struct.js
src/Struct.spec
+0
-0
0 additions, 0 deletions
src/Struct.spec
with
79 additions
and
52 deletions
src/
Operations
.js
→
src/
Struct
.js
+
79
−
52
View file @
8f63147d
...
...
@@ -29,25 +29,31 @@ var Struct = {
}
},
Insert
:
{
create
:
function
*
(
op
:
Op
,
content
:
any
,
left
:
Insert
,
right
:
Insert
,
parent
:
List
)
:
Insert
{
op
.
left
=
left
?
left
.
id
:
null
;
/*{
content: any,
left: Id,
right: Id,
parent: Id,
parentSub: string (optional)
}
*/
create
:
function
*
(
op
:
Op
)
:
Insert
{
if
(
op
.
left
===
undefined
||
op
.
right
===
undefined
||
op
.
parent
===
undefined
)
{
throw
new
Error
(
"
You must define left, right, and parent!
"
);
}
op
.
origin
=
op
.
left
;
op
.
right
=
right
?
right
.
id
:
null
;
op
.
parent
=
parent
.
id
;
op
.
struct
=
"
Insert
"
;
yield
*
Struct
.
Operation
.
create
.
call
(
this
,
op
);
if
(
left
!=
null
)
{
left
.
right
=
op
.
id
;
yield
*
this
.
setOperation
(
left
);
if
(
op
.
left
!=
null
)
{
op
.
left
.
right
=
op
.
id
;
yield
*
this
.
setOperation
(
op
.
left
);
}
if
(
right
!=
null
)
{
right
.
left
=
op
.
id
;
yield
*
this
.
setOperation
(
right
);
if
(
op
.
right
!=
null
)
{
op
.
right
.
left
=
op
.
id
;
yield
*
this
.
setOperation
(
op
.
right
);
}
return
op
;
},
...
...
@@ -113,16 +119,42 @@ var Struct = {
break
;
}
}
// reconnect..
var
left
=
this
.
getOperation
(
op
.
left
);
var
right
=
this
.
getOperation
(
op
.
right
);
left
.
right
=
op
.
id
;
right
.
left
=
op
.
id
;
var
left
=
null
;
var
right
=
null
;
if
(
op
.
left
!=
null
)
{
left
=
this
.
getOperation
(
op
.
left
);
left
.
right
=
op
.
id
;
yield
*
this
.
setOperation
(
left
);
}
if
(
op
.
right
!=
null
)
{
right
=
this
.
getOperation
(
op
.
right
);
right
.
left
=
op
.
id
;
yield
*
this
.
setOperation
(
right
);
}
op
.
left
=
left
;
op
.
right
=
right
;
yield
*
this
.
setOperation
(
left
);
yield
*
this
.
setOperation
(
right
);
yield
*
this
.
setOperation
(
op
);
// notify parent
var
parent
=
this
.
getOperation
(
op
.
parent
);
if
(
op
.
parentSub
!=
null
)
{
if
(
right
==
null
)
{
parent
.
map
[
op
.
parentSub
]
=
op
.
id
;
yield
*
this
.
setOperation
(
parent
);
}
}
else
{
if
(
right
==
null
||
left
==
null
)
{
if
(
right
==
null
)
{
parent
.
end
=
op
.
id
;
}
if
(
left
==
null
)
{
parent
.
start
=
op
.
id
;
}
yield
*
this
.
setOperation
(
parent
);
}
}
}
},
List
:
{
...
...
@@ -166,53 +198,48 @@ var Struct = {
var
o
=
yield
*
Struct
.
List
.
ref
.
call
(
this
,
op
,
pos
);
var
or
=
yield
*
this
.
getOperation
(
o
.
right
);
for
(
var
content
of
contents
)
{
o
=
yield
*
Struct
.
Insert
.
create
.
call
(
this
,
{},
content
,
o
,
or
,
op
);
var
insert
=
{
left
:
o
,
right
:
or
,
content
:
content
,
parent
:
op
};
o
=
yield
*
Struct
.
Insert
.
create
.
call
(
this
,
insert
);
}
}
},
Map
:
{
create
:
function
*
(
op
:
Op
){
op
.
start
=
null
;
op
.
end
=
null
;
create
:
function
*
(
op
:
Op
){
op
.
map
=
{};
op
.
struct
=
"
Map
"
;
return
yield
*
Struct
.
Operation
.
create
.
call
(
this
,
op
);
},
requiredOps
:
function
(
op
,
ids
){
if
(
op
.
start
!=
null
)
{
ids
.
push
(
op
.
start
);
}
if
(
op
.
end
!=
null
){
ids
.
push
(
op
.
end
);
for
(
var
end
of
op
.
map
)
{
ids
.
push
(
end
);
}
return
ids
;
},
execute
:
function
*
()
{
// nop
},
ref
:
function
*
(
op
:
Op
,
pos
:
number
)
:
Insert
{
var
o
=
op
.
start
;
while
(
pos
!==
0
||
o
!=
null
)
{
o
=
(
yield
*
this
.
getOperation
(
o
)).
right
;
pos
--
;
}
return
(
o
==
null
)
?
null
:
yield
*
this
.
getOperation
(
o
);
get
:
function
*
(
op
,
name
)
{
return
yield
*
this
.
getOperation
(
op
.
map
[
name
].
end
);
},
map
:
function
*
(
o
:
Op
,
f
:
Function
)
:
Array
<
any
>
{
o
=
o
.
start
;
var
res
=
[];
while
(
o
!=
null
)
{
var
operation
=
yield
*
this
.
getOperation
(
o
);
res
.
push
(
f
(
operation
.
content
));
o
=
operation
.
right
;
}
return
res
;
},
insert
:
function
*
(
op
,
pos
:
number
,
contents
:
Array
<
any
>
)
{
var
o
=
yield
*
Struct
.
List
.
ref
.
call
(
this
,
op
,
pos
);
var
or
=
yield
*
this
.
getOperation
(
o
.
right
);
for
(
var
content
of
contents
)
{
o
=
yield
*
Struct
.
Insert
.
create
.
call
(
this
,
{},
content
,
o
,
or
,
op
);
}
set
:
function
*
(
op
,
name
,
value
)
{
var
end
=
op
.
map
[
name
];
if
(
end
==
null
)
{
end
=
null
;
op
.
map
[
name
]
=
end
;
}
var
insert
=
{
left
:
end
,
right
:
null
,
content
:
value
,
parent
:
op
.
id
,
parentSub
:
name
};
yield
*
Struct
.
Insert
.
create
.
call
(
this
,
insert
);
}
}
};
This diff is collapsed.
Click to expand it.
src/
Operations
.spec
→
src/
Struct
.spec
+
0
−
0
View file @
8f63147d
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment