FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/src/main/java/com/list/SimpleSkipList.java at master · verifyCode/algorithms · GitHub
verifyCode
algorithms
Repository navigation
Code
Issues
Pull requests
2
(2)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
src
/
main
/
java
/
com
/
list
/
SimpleSkipList.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (60 loc) · 1.69 KB
Breadcrumbs
algorithms
/
src
/
main
/
java
/
com
/
list
/
SimpleSkipList.java
Copy path
File metadata and controls
74 lines (60 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package
com
.
list
;
import
java
.
util
.
Random
;
/**
* @author xjn
* @since 2020-02-23
*/
public
class
SimpleSkipList
{
private
final
static
byte
HEAD_NODE
= (
byte
) -
1
;
private
final
static
byte
DATA_NODE
= (
byte
)
0
;
private
final
static
byte
TAIL_NODE
= (
byte
)
1
;
private
static
class
Node
{
private
Integer
value
;
private
Node
up
,
down
,
left
,
right
;
private
byte
flag
;
public
Node
(
Integer
value
,
byte
flag
) {
this
.
value
=
value
;
this
.
flag
=
flag
;
}
public
Node
(
Integer
value
) {
this
(
value
,
DATA_NODE
);
}
}
private
Node
head
;
private
Node
tail
;
private
int
size
;
private
int
height
;
private
Random
random
;
public
SimpleSkipList
() {
this
.
head
=
new
Node
(
null
,
HEAD_NODE
);
this
.
tail
=
new
Node
(
null
,
TAIL_NODE
);
head
.
left
=
tail
;
tail
.
right
=
head
;
this
.
random
=
new
Random
(
System
.
currentTimeMillis
());
}
private
Node
find
(
Integer
element
) {
Node
current
=
head
;
for
(; ; ) {
while
(
current
.
right
.
flag
!=
TAIL_NODE
&&
current
.
right
.
value
<
element
) {
current
=
current
.
right
;
}
if
(
current
.
down
!=
null
) {
current
=
current
.
down
;
}
else
{
break
;
}
}
//current.value <= element < current.right(if exist)
return
current
;
}
public
boolean
contains
(
Integer
element
) {
Node
node
=
this
.
find
(
element
);
return
element
==
node
.
value
;
}
public
boolean
isEmpty
() {
return
this
.
size
==
0
;
}
public
int
getSize
() {
return
this
.
size
;
}
}
Back
|
FazBrowse Home
|
New Git URL