Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
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
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
cs525-sp18-g07
spark
Commits
0b35051f
Commit
0b35051f
authored
11 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Address some comments on code clarity
parent
4acbc5af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/scala/org/apache/spark/util/AppendOnlyMap.scala
+11
-9
11 additions, 9 deletions
.../src/main/scala/org/apache/spark/util/AppendOnlyMap.scala
with
11 additions
and
9 deletions
core/src/main/scala/org/apache/spark/util/AppendOnlyMap.scala
+
11
−
9
View file @
0b35051f
...
...
@@ -33,6 +33,7 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64) extends Iterable[(K, V)] wi
require
(
initialCapacity
>=
1
,
"Invalid initial capacity"
)
private
var
capacity
=
nextPowerOf2
(
initialCapacity
)
private
var
mask
=
capacity
-
1
private
var
curSize
=
0
// Holds keys and values in the same array for memory locality; specifically, the order of
...
...
@@ -51,13 +52,14 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64) extends Iterable[(K, V)] wi
if
(
k
.
eq
(
null
))
{
return
nullValue
}
val
mask
=
capacity
-
1
var
pos
=
rehash
(
k
.
hashCode
)
&
mask
var
i
=
1
while
(
true
)
{
val
curKey
=
data
(
2
*
pos
)
if
(
curKey
.
eq
(
k
)
||
curKey
.
eq
(
null
)
||
curKey
==
k
)
{
if
(
k
.
eq
(
curKey
)
||
k
==
curKey
)
{
return
data
(
2
*
pos
+
1
).
asInstanceOf
[
V
]
}
else
if
(
curKey
.
eq
(
null
))
{
return
null
.
asInstanceOf
[
V
]
}
else
{
val
delta
=
i
pos
=
(
pos
+
delta
)
&
mask
...
...
@@ -68,7 +70,7 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64) extends Iterable[(K, V)] wi
}
/** Set the value for a key */
def
update
(
key
:
K
,
value
:
V
)
{
def
update
(
key
:
K
,
value
:
V
)
:
Unit
=
{
val
k
=
key
.
asInstanceOf
[
AnyRef
]
if
(
k
.
eq
(
null
))
{
if
(!
haveNullValue
)
{
...
...
@@ -98,21 +100,20 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64) extends Iterable[(K, V)] wi
haveNullValue
=
true
return
nullValue
}
val
mask
=
capacity
-
1
var
pos
=
rehash
(
k
.
hashCode
)
&
mask
var
i
=
1
while
(
true
)
{
val
curKey
=
data
(
2
*
pos
)
if
(
curKey
.
eq
(
null
))
{
if
(
k
.
eq
(
curKey
)
||
k
==
curKey
)
{
val
newValue
=
updateFunc
(
true
,
data
(
2
*
pos
+
1
).
asInstanceOf
[
V
])
data
(
2
*
pos
+
1
)
=
newValue
.
asInstanceOf
[
AnyRef
]
return
newValue
}
else
if
(
curKey
.
eq
(
null
))
{
val
newValue
=
updateFunc
(
false
,
null
.
asInstanceOf
[
V
])
data
(
2
*
pos
)
=
k
data
(
2
*
pos
+
1
)
=
newValue
.
asInstanceOf
[
AnyRef
]
incrementSize
()
return
newValue
}
else
if
(
curKey
.
eq
(
k
)
||
curKey
==
k
)
{
val
newValue
=
updateFunc
(
true
,
data
(
2
*
pos
+
1
).
asInstanceOf
[
V
])
data
(
2
*
pos
+
1
)
=
newValue
.
asInstanceOf
[
AnyRef
]
return
newValue
}
else
{
val
delta
=
i
pos
=
(
pos
+
delta
)
&
mask
...
...
@@ -219,6 +220,7 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64) extends Iterable[(K, V)] wi
}
data
=
newData
capacity
=
newCapacity
mask
=
newCapacity
-
1
}
private
def
nextPowerOf2
(
n
:
Int
)
:
Int
=
{
...
...
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