Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
a6b1b319
Unverified
Commit
a6b1b319
authored
8 years ago
by
kaldoran
Browse files
Options
Downloads
Patches
Plain Diff
Adding ZCurve algorithm
parent
ae387981
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/indexation/pht.h
+5
-27
5 additions, 27 deletions
include/opendht/indexation/pht.h
src/Makefile.am
+1
-1
1 addition, 1 deletion
src/Makefile.am
src/indexation/pht.cpp
+53
-34
53 additions, 34 deletions
src/indexation/pht.cpp
with
59 additions
and
62 deletions
include/opendht/indexation/pht.h
+
5
−
27
View file @
a6b1b319
...
...
@@ -147,6 +147,7 @@ struct Prefix {
Prefix
swapBit
(
size_t
bit
)
const
{
if
(
bit
>=
content_
.
size
()
*
8
)
throw
std
::
out_of_range
(
"bit larger than prefix size."
);
}
void
swapFlagBit
(
size_t
bit
)
{
swapBit
(
flags_
,
bit
);
...
...
@@ -177,7 +178,9 @@ struct Prefix {
Blob
flags_
{};
Blob
content_
{};
private
:
std
::
string
blobToString
(
const
Blob
&
bl
)
const
{
std
::
stringstream
ss
;
...
...
@@ -392,32 +395,7 @@ private:
std
::
shared_ptr
<
unsigned
>
max_common_prefix_len
,
int
start
=
-
1
,
bool
all_values
=
false
);
Prefix
zcurve
(
const
std
::
vector
<
Prefix
>&
all_prefix
)
const
{
Prefix
p
;
if
(
all_prefix
.
size
()
==
1
)
return
all_prefix
[
0
];
for
(
size_t
j
=
0
,
bit
=
0
;
j
<
all_prefix
[
0
].
content_
.
size
();
j
++
)
{
uint8_t
mask
=
0x80
;
for
(
int
i
=
0
;
i
<
8
;
)
{
uint8_t
content
=
0
;
uint8_t
flags
=
0
;
for
(
int
k
=
0
;
k
<
8
;
k
++
,
bit
++
)
{
auto
diff
=
k
-
i
;
auto
x
=
all_prefix
[
bit
].
content_
[
j
]
&
mask
;
auto
y
=
all_prefix
[
bit
].
flags_
[
j
]
&
mask
;
content
|=
(
diff
>=
0
)
?
x
>>
diff
:
x
<<
std
::
abs
(
diff
);
flags
|=
(
diff
>=
0
)
?
y
>>
diff
:
y
<<
std
::
abs
(
diff
);
if
(
bit
==
all_prefix
.
size
()
-
1
)
{
bit
=
-
1
;
++
i
;
mask
>>=
1
;
}
}
p
.
content_
.
push_back
(
content
);
p
.
flags_
.
push_back
(
flags
);
p
.
size_
+=
8
;
}
}
return
p
;
}
Prefix
zcurve
(
const
std
::
vector
<
Prefix
>&
all_prefix
)
const
;
/**
* Linearizes the key into a unidimensional key. A pht only takes
...
...
@@ -459,7 +437,7 @@ private:
size_t
foundSplitLocation
(
Prefix
compared
,
std
::
shared_ptr
<
std
::
vector
<
std
::
shared_ptr
<
IndexEntry
>>>
vals
)
{
for
(
size_t
i
=
0
;
i
<
compared
.
content_
.
size
()
*
8
-
1
;
i
++
)
for
(
auto
const
&
v
:
*
vals
)
if
(
Prefix
(
v
->
prefix
).
isActive
Bit
(
i
)
!=
compared
.
isActive
Bit
(
i
)
)
if
(
Prefix
(
v
->
prefix
).
is
ContentBit
Active
(
i
)
!=
compared
.
is
ContentBit
Active
(
i
)
)
return
i
+
1
;
return
compared
.
content_
.
size
()
*
8
-
1
;
...
...
This diff is collapsed.
Click to expand it.
src/Makefile.am
+
1
−
1
View file @
a6b1b319
...
...
@@ -4,7 +4,7 @@ lib_LTLIBRARIES = libopendht.la
AM_CPPFLAGS
=
-I
../include/opendht
libopendht_la_CXXFLAGS
=
@CXXFLAGS@
libopendht_la_LDFLAGS
=
@LDFLAGS@ @GNUTLS_LIBS@ @nettle_LIBS@
-version-info
6:0:2
libopendht_la_LDFLAGS
=
@LDFLAGS@ @GNUTLS_LIBS@ @nettle_LIBS@
libopendht_la_LIBADD
=
./argon2/libargon2.la
libopendht_la_SOURCES
=
\
...
...
This diff is collapsed.
Click to expand it.
src/indexation/pht.cpp
+
53
−
34
View file @
a6b1b319
...
...
@@ -216,7 +216,6 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
on_done
(
true
);
}
},
pht_filter
);
}
else
{
on_done
(
true
);
}
...
...
@@ -286,7 +285,7 @@ void Pht::insert(Prefix kp, IndexEntry entry, std::shared_ptr<int> lo, std::shar
updateCanary
(
*
p
);
checkPhtUpdate
(
*
p
,
entry
,
time_p
);
cache_
.
insert
(
*
p
);
dht_
->
put
(
p
->
hash
(),
std
::
move
(
entry
),
done_cb
/*
, time_p
*/
);
dht_
->
put
(
p
->
hash
(),
std
::
move
(
entry
),
done_cb
,
time_p
);
};
if
(
not
check_split
or
final_prefix
->
size_
==
kp
.
size_
)
{
...
...
@@ -302,30 +301,50 @@ void Pht::insert(Prefix kp, IndexEntry entry, std::shared_ptr<int> lo, std::shar
);
}
Prefix
linearize
(
Key
k
)
const
{
if
(
not
validKey
(
k
))
{
throw
std
::
invalid_argument
(
INVALID_KEY
);
}
std
::
vector
<
Prefix
>
all_prefix
;
auto
max
=
std
::
max_element
(
keySpec_
.
begin
(),
keySpec_
.
end
(),
[](
const
std
::
pair
<
string
,
size_t
>&
a
,
const
std
::
pair
<
string
,
size_t
>&
b
)
{
return
a
.
second
<
b
.
second
;
});
Prefix
Pht
::
zcurve
(
const
std
::
vector
<
Prefix
>&
all_prefix
)
const
{
Prefix
p
;
for
(
auto
i
=
0
;
i
<
k
.
size
;
i
++
)
{
Prefix
p
=
Blob
{
k
.
begin
()
->
second
.
begin
(),
k
.
begin
()
->
second
.
end
()};
p
.
addPaddingContent
(
max
);
p
.
updateFlags
();
if
(
all_prefix
.
size
()
==
1
)
return
all_prefix
[
0
];
for
(
size_t
j
=
0
,
bit
=
0
;
j
<
all_prefix
[
0
].
content_
.
size
();
j
++
)
{
uint8_t
mask
=
0x80
;
for
(
int
i
=
0
;
i
<
8
;
)
{
uint8_t
flags
=
0
;
uint8_t
content
=
0
;
for
(
int
k
=
0
;
k
<
8
;
k
++
,
bit
++
)
{
auto
diff
=
k
-
i
;
all_prefix
.
push_back
(
p
);
auto
x
=
all_prefix
[
bit
].
content_
[
j
]
&
mask
;
auto
y
=
all_prefix
[
bit
].
flags_
[
j
]
&
mask
;
content
|=
(
diff
>=
0
)
?
x
>>
diff
:
x
<<
std
::
abs
(
diff
);
flags
|=
(
diff
>=
0
)
?
y
>>
diff
:
y
<<
std
::
abs
(
diff
);
if
(
bit
==
all_prefix
.
size
()
-
1
)
{
bit
=
-
1
;
++
i
;
mask
>>=
1
;
}
}
return
zcurve
(
all_prefix
);
/*
virtual Prefix linearize(Key k) const {
p
.
content_
.
push_back
(
content
);
p
.
flags_
.
push_back
(
flags
);
p
.
size_
+=
8
;
}
}
return
p
;
}
Prefix
Pht
::
linearize
(
Key
k
)
const
{
if
(
not
validKey
(
k
))
{
throw
std
::
invalid_argument
(
INVALID_KEY
);
}
std
::
vector
<
Prefix
>
all_prefix
;
all_prefix
.
reserve
(
k
.
size
());
auto
max
=
std
::
max_element
(
keySpec_
.
begin
(),
keySpec_
.
end
(),
[&
](const std::pair<std::string, size_t>& a, const std::pair<std::string, size_t>& b) {
[
](
const
std
::
pair
<
std
::
string
,
size_t
>&
a
,
const
std
::
pair
<
std
::
string
,
size_t
>&
b
)
{
return
a
.
second
<
b
.
second
;
})
->
second
+
1
;
...
...
@@ -333,15 +352,12 @@ Prefix linearize(Key k) const {
Prefix
p
=
Blob
{
it
.
second
.
begin
(),
it
.
second
.
end
()};
p
.
addPaddingContent
(
max
);
p
.
updateFlags
();
all_prefix.push_back(p);
auto bit_loc = p.size_ + 1;
for ( auto i = p.content_.size(); i < keySpec_.begin()->second + 1; i++ )
p.content_.push_back(0);
all_prefix
.
emplace_back
(
std
::
move
(
p
));
}
return
zcurve
(
all_prefix
);
};*/
};
}
void
Pht
::
getRealPrefix
(
std
::
shared_ptr
<
Prefix
>
p
,
IndexEntry
entry
,
RealInsertCallback
end_cb
)
{
...
...
@@ -428,9 +444,12 @@ void Pht::split(Prefix insert, std::shared_ptr<std::vector<std::shared_ptr<Index
auto
loc
=
foundSplitLocation
(
full
,
vals
);
auto
prefix_to_insert
=
std
::
make_shared
<
Prefix
>
(
full
.
getPrefix
(
loc
));
std
::
cerr
<<
" Split loc "
<<
loc
<<
" full"
<<
full
.
toString
()
<<
" size "
<<
full
.
size_
<<
std
::
endl
;
for
(;
loc
!=
insert
.
size_
-
1
;
loc
--
)
for
(;
loc
!=
insert
.
size_
-
1
;
loc
--
)
{
std
::
cerr
<<
"loc "
<<
full
.
getPrefix
(
loc
).
toString
()
<<
std
::
endl
;
updateCanary
(
full
.
getPrefix
(
loc
));
}
end_cb
(
prefix_to_insert
,
entry
);
}
...
...
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