Skip to content

Commit

Permalink
Merge pull request #1 from karasikov/master
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
Chris Barber authored May 6, 2019
2 parents 5edce05 + a395939 commit 9b0f578
Showing 1 changed file with 72 additions and 75 deletions.
147 changes: 72 additions & 75 deletions include/internal/wt_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,20 @@ namespace dyn{

template<class Vector>
void push_many(const Vector& values) {
map<char_type, vector<bool>> Bs{};
set<char_type> partition{};


for (ulint i = 0; i < values.size(); ++i) {
auto c = values[i];
if(!ae.char_exists(c))
ae.encode(c);
}
partition = ae.keys();

for(auto c : partition) {
Bs[c] = ae.encode(c);
map<char_type, vector<bool>> path_to_leaf;
for(char_type c : ae.keys()) {
path_to_leaf[c] = ae.encode(c);
}

#pragma omp parallel
#pragma omp master
root.push_many(std::move(Bs), values, std::move(partition));
root.push_many(std::move(path_to_leaf), values);
n += values.size();
}

Expand Down Expand Up @@ -465,79 +461,80 @@ namespace dyn{

}

template<class Vector>
void push_many(map<char_type, vector<bool>>&& Bs,
const Vector& values,
set<char_type> partition,
ulint j=0,
ulint offset=0) {

if(partition.size()==1){
//this node must be a leaf
assert(bv.size()==0);

auto c = *partition.begin();
assert(j==Bs[c].size());

if(is_leaf()){
//if it's already marked as leaf, check
//that the label is correct
assert(c==label());
}else{
//else, mark node as leaf
make_leaf(c);
}
return;
template<class Vector>
void push_many(map<char_type, vector<bool>>&& Bs,
const Vector& values,
ulint j=0,
ulint offset=0) {

if(Bs.size()==1){
//this node must be a leaf
assert(bv.size()==0);

auto c = Bs.begin()->first;
assert(j==Bs[c].size());

if(is_leaf()){
//if it's already marked as leaf, check
//that the label is correct
assert(c==label());
}else{
//else, mark node as leaf
make_leaf(c);
}
return;
}

assert(not is_leaf());

bool t0 = false, t1 = false;

for(ulint idx = offset; idx < values.size(); ++idx) {
auto c = values[idx];
if (partition.find(c) != partition.end()) {
auto B = Bs[c];

bool b = B[j];
bv.push_back(b);

if(b){
if(not t1){
t1 = true;

if(not has_child1())
child1_ = new node(this);

set<char_type> new_partition;
for_each(partition.begin(), partition.end(), [&](char_type c) {
if (Bs[c][j])
new_partition.insert(c);
});
#pragma omp task
child1_->push_many(std::move(Bs), values, new_partition, j+1, idx);
}
}else{
if(not t0){
t0 = true;

if(not has_child0())
child0_ = new node(this);

set<char_type> new_partition;
for_each(partition.begin(), partition.end(), [&](char_type c) {
if (!Bs[c][j])
new_partition.insert(c);
});
#pragma omp task
child0_->push_many(std::move(Bs), values, new_partition, j+1, idx);
}
}
}
bool t0 = false;
bool t1 = false;

for(ulint idx = offset; idx < values.size(); ++idx) {
auto c = values[idx];
if (!Bs.count(c))
continue;

auto B = Bs[c];

bool b = B[j];
bv.push_back(b);

if(b){
if(not t1){
t1 = true;

if(not has_child1())
child1_ = new node(this);

map<char_type, vector<bool>> new_Bs;
for_each(Bs.begin(), Bs.end(), [&new_Bs](const auto &pair) {
if (pair.second[j])
new_Bs.insert(pair);
});
#pragma omp task
child1_->push_many(std::move(new_Bs), values, j+1, idx);
}
}else{
if(not t0){
t0 = true;

if(not has_child0())
child0_ = new node(this);

map<char_type, vector<bool>> new_Bs;
for_each(partition.begin(), partition.end(), [&](const auto &pair) {
if (!pair.second[j])
new_Bs.insert(pair);
});
#pragma omp task
child0_->push_many(std::move(new_Bs), values, j+1, idx);
}
}
}

#pragma omp taskwait
}
#pragma omp taskwait
}

/*
* remove code B[j,...,B.size()-1] from position i. This code is associated
Expand Down

0 comments on commit 9b0f578

Please sign in to comment.