Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
385e8f86
Commit
385e8f86
authored
Jan 04, 2018
by
Tiago Peixoto
Browse files
dynamic_sampler.hh: Fix rebuild()
parent
621322fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph/generation/dynamic_sampler.hh
View file @
385e8f86
...
...
@@ -50,8 +50,8 @@ public:
template
<
class
RNG
>
const
Value
&
sample
(
RNG
&
rng
)
const
{
uniform_real_distribution
<>
sample
(
0
,
1
);
double
u
=
_tree
[
0
]
*
sample
(
rng
),
c
=
0
;
uniform_real_distribution
<>
sample
(
0
,
_tree
[
0
]
);
double
u
=
sample
(
rng
),
c
=
0
;
size_t
pos
=
0
;
while
(
_idx
[
pos
]
==
numeric_limits
<
size_t
>::
max
())
...
...
@@ -127,13 +127,24 @@ public:
_n_items
--
;
}
void
clear
()
void
clear
(
bool
shrink
)
{
_items
.
clear
();
_ipos
.
clear
();
_tree
.
clear
();
_idx
.
clear
();
_back
=
0
;
_free
.
clear
();
_valid
.
clear
();
if
(
shrink
)
{
_items
.
shrink_to_fit
();
_ipos
.
shrink_to_fit
();
_tree
.
shrink_to_fit
();
_idx
.
shrink_to_fit
();
_free
.
shrink_to_fit
();
_valid
.
shrink_to_fit
();
}
_back
=
0
;
_n_items
=
0
;
}
...
...
@@ -150,7 +161,7 @@ public:
probs
.
push_back
(
_tree
[
i
]);
}
clear
();
clear
(
true
);
for
(
size_t
i
=
0
;
i
<
items
.
size
();
++
i
)
insert
(
items
[
i
],
probs
[
i
]);
...
...
@@ -163,7 +174,7 @@ public:
bool
is_valid
(
size_t
i
)
const
{
return
(
i
<
_items
.
size
()
&&
_valid
[
i
]);
return
(
(
i
<
_items
.
size
()
)
&&
_valid
[
i
]);
}
const
auto
&
items
()
const
...
...
@@ -228,7 +239,7 @@ private:
vector
<
Value
>
_items
;
vector
<
size_t
>
_ipos
;
// position of the item in the tree
vector
<
size_t
>
_ipos
;
// position of the item in the tree
vector
<
double
>
_tree
;
// tree nodes with weight sums
vector
<
size_t
>
_idx
;
// index in _items
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment