Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RAMCloud
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
adilr3
RAMCloud
Commits
8450af1f
Commit
8450af1f
authored
3 years ago
by
root
Browse files
Options
Downloads
Patches
Plain Diff
my hash map
parent
01798a5c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/HashMap.h
+150
-0
150 additions, 0 deletions
src/HashMap.h
src/HashNode.h
+84
-0
84 additions, 0 deletions
src/HashNode.h
src/ObjectManager.cc
+1
-0
1 addition, 0 deletions
src/ObjectManager.cc
src/ObjectManager.h
+9
-0
9 additions, 0 deletions
src/ObjectManager.h
with
244 additions
and
0 deletions
src/HashMap.h
0 → 100644
+
150
−
0
View file @
8450af1f
#pragma once
/**
* Copyright 2017 HashMap Development Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include
"HashNode.h"
#include
<cstddef>
#include
"Key.h"
#include
"Buffer.h"
#define TABLE_SIZE 50000
namespace
RAMCloud
{
class
HashMap
{
public:
HashMap
()
:
table
()
{}
~
HashMap
()
{
// destroy all buckets one by one
for
(
size_t
i
=
0
;
i
<
TABLE_SIZE
;
++
i
)
{
HashNode
*
entry
=
table
[
i
];
while
(
entry
!=
NULL
)
{
HashNode
*
prev
=
entry
;
entry
=
entry
->
getNext
();
delete
prev
;
}
table
[
i
]
=
NULL
;
}
}
bool
get
(
Key
&
key
,
Buffer
&
value
)
{
unsigned
long
hashValue
=
hashFunc
(
key
);
// HashNode *entry = table[hashValue];
HashNode
*
entry
=
table
[
hashValue
];
while
(
entry
!=
NULL
)
{
if
(
entry
->
getKey
()
==
key
)
{
void
**
ptr
;
entry
->
getValue
().
peek
(
0
,
ptr
);
value
.
appendCopy
(
*
ptr
,
entry
->
getValue
().
size
());
// verify if should be dereferenced
return
true
;
}
entry
=
entry
->
getNext
();
}
return
false
;
}
void
put
(
Key
&
key
,
const
Buffer
&
value
)
{
unsigned
long
hashValue
=
hashFunc
(
key
);
HashNode
*
prev
=
NULL
;
HashNode
*
entry
=
table
[
hashValue
];
while
(
entry
!=
NULL
&&
entry
->
getKey
()
!=
key
)
{
prev
=
entry
;
entry
=
entry
->
getNext
();
}
if
(
entry
==
NULL
)
{
entry
=
new
HashNode
(
key
,
value
);
if
(
prev
==
NULL
)
{
// insert as first bucket
table
[
hashValue
]
=
entry
;
}
else
{
prev
->
setNext
(
entry
);
}
}
else
{
// just update the value
entry
->
setValue
(
value
);
}
}
void
remove
(
Key
&
key
)
{
unsigned
long
hashValue
=
hashFunc
(
key
);
HashNode
*
prev
=
NULL
;
HashNode
*
entry
=
table
[
hashValue
];
while
(
entry
!=
NULL
&&
entry
->
getKey
()
!=
key
)
{
prev
=
entry
;
entry
=
entry
->
getNext
();
}
if
(
entry
==
NULL
)
{
// key not found
return
;
}
else
{
if
(
prev
==
NULL
)
{
// remove first bucket of the list
table
[
hashValue
]
=
entry
->
getNext
();
}
else
{
prev
->
setNext
(
entry
->
getNext
());
}
delete
entry
;
}
}
private
:
HashMap
(
const
HashMap
&
other
);
const
HashMap
&
operator
=
(
const
HashMap
&
other
);
// hash table
HashNode
*
table
[
TABLE_SIZE
];
unsigned
long
hashFunc
(
Key
&
k
)
const
{
return
k
.
getHash
();
}
};
}
This diff is collapsed.
Click to expand it.
src/HashNode.h
0 → 100644
+
84
−
0
View file @
8450af1f
#pragma once
/**
* Copyright 2017 HashMap Development Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include
<cstddef>
#include
"Key.h"
#include
"Buffer.h"
namespace
RAMCloud
{
// Hash node class template
// template <typename Key, typename Buffer>
class
HashNode
{
private:
// key-value pair
// next bucket with the same key
public:
Key
_key
;
Buffer
_value
;
HashNode
*
_next
;
// disallow copy and assignment
HashNode
(
const
HashNode
&
);
HashNode
&
operator
=
(
const
HashNode
&
);
HashNode
(
const
Key
&
key
,
Buffer
&
value
)
:
_key
(
key
.
getTableId
(),
key
.
getStringKey
(),
key
.
getStringKeyLength
()
),
_value
(),
_next
(
NULL
)
{
void
**
ptr
;
value
.
peek
(
0
,
ptr
);
_value
.
appendCopy
(
*
ptr
,
value
.
size
());
}
Key
getKey
()
const
{
return
_key
;
}
Buffer
getValue
()
const
{
return
_value
;
}
void
setValue
(
Buffer
&
value
)
{
void
**
ptr
;
value
.
peek
(
0
,
ptr
);
_value
.
appendCopy
(
*
ptr
,
value
.
size
());
// _value = value;
}
HashNode
*
getNext
()
const
{
return
_next
;
}
void
setNext
(
HashNode
*
next
)
{
_next
=
next
;
}
};
}
This diff is collapsed.
Click to expand it.
src/ObjectManager.cc
+
1
−
0
View file @
8450af1f
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include
"WallTime.h"
#include
"WallTime.h"
#include
"MasterService.h"
#include
"MasterService.h"
#include
<emmintrin.h>
// _mm_clflush and _mm_mfence
#include
<emmintrin.h>
// _mm_clflush and _mm_mfence
#include
"HashMap.h"
namespace
RAMCloud
{
namespace
RAMCloud
{
...
...
This diff is collapsed.
Click to expand it.
src/ObjectManager.h
+
9
−
0
View file @
8450af1f
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#include
"MasterTableMetadata.h"
#include
"MasterTableMetadata.h"
#include
"UnackedRpcResults.h"
#include
"UnackedRpcResults.h"
#include
"LockTable.h"
#include
"LockTable.h"
#include
"HashMap.h"
namespace
RAMCloud
{
namespace
RAMCloud
{
...
@@ -416,6 +417,14 @@ class ObjectManager : public LogEntryHandlers,
...
@@ -416,6 +417,14 @@ class ObjectManager : public LogEntryHandlers,
*/
*/
int
tombstoneProtectorCount
;
int
tombstoneProtectorCount
;
/**
* This hash table maps the key to a pointer to the value in DRAM.
*
*/
HashMap
cacheTable
;
friend
class
CleanerCompactionBenchmark
;
friend
class
CleanerCompactionBenchmark
;
friend
class
ObjectManagerBenchmark
;
friend
class
ObjectManagerBenchmark
;
...
...
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