1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
//***************************************************************************
//* Copyright (c) 2015 Saint Petersburg State University
//* Copyright (c) 2011-2014 Saint Petersburg Academic University
//* All Rights Reserved
//* See file LICENSE for details.
//***************************************************************************
#pragma once
#include "utils/ph_map/perfect_hash_map.hpp"
#include "edge_info_updater.hpp"
#include "edge_position_index.hpp"
#include <folly/SmallLocks.h>
namespace debruijn_graph {
template<class IdType>
class EdgeInfoStorage {
public:
typedef vector<EdgeInfo<IdType>> Content;
typedef typename Content::iterator iterator;
typedef typename Content::const_iterator const_iterator;
Content content_;
folly::MicroSpinLock lock_;
EdgeInfoStorage(const Content &content) : content_(content) {
lock_.init();
}
EdgeInfoStorage() {
lock_.init();
}
EdgeInfo<IdType> &operator[](size_t i) {
return content_[i];
}
iterator begin() {
return content_.begin();
}
iterator end() {
return content_.end();
}
const_iterator begin() const {
return content_.cbegin();
}
const_iterator end() const {
return content_.cend();
}
iterator find(const EdgeInfo<IdType> &info) {
return content_.find(info);
}
const_iterator find(const EdgeInfo<IdType> &info) const {
return content_.find(info);
}
void push_back(const EdgeInfo<IdType> &info) {
folly::MSLGuard g(lock_);
content_.push_back(info);
}
template<class... Args>
void emplace_back(Args&&... args) {
folly::MSLGuard g(lock_);
content_.emplace_back(std::forward<Args>(args)...);
}
size_t size() const{
return content_.size();
}
bool valid() const {
//what's invalid edge info storage?
return true;
}
EdgeInfoStorage conjugate(size_t k) const {
EdgeInfoStorage result;
for(auto it = content_.rbegin(); it != content_.rend(); ++it) {
result.push_back(it->conjugate(k));
}
return result;
}
};
//todo it is not handling graph events!!!
template<class IdType, class Seq = RtSeq,
class traits = utils::kmer_index_traits<Seq>, class StoringType = utils::SimpleStoring >
class DeBruijnEdgeMultiIndex : public utils::KeyStoringMap<Seq, EdgeInfoStorage<IdType>, traits, StoringType > {
typedef utils::KeyStoringMap<Seq, EdgeInfoStorage<IdType>, traits, StoringType > base;
public:
typedef StoringType storing_type;
typedef typename base::traits_t traits_t;
typedef typename base::KMer KMer;
typedef typename base::KMerIdx KMerIdx;
typedef typename base::KeyWithHash KeyWithHash;
typedef EdgeInfoStorage<IdType> Value;
using base::ConstructKWH;
// typedef typename base::IdType IdType;
//todo move this typedef up in hierarchy (need some c++ tricks)
DeBruijnEdgeMultiIndex(unsigned k)
: base(k) {
INFO("Constructing multi-kmer index");
}
~DeBruijnEdgeMultiIndex() {}
Value get(const KeyWithHash &kwh) const {
VERIFY(contains(kwh));
return base::get_value(kwh);
}
bool contains(const KeyWithHash &kwh) const {
if (!base::valid(kwh))
return false;
return this->get_raw_value_reference(kwh).valid();
}
bool valid(const KMer &kmer) const {
KeyWithHash kwh = base::ConstructKWH(kmer);
return base::valid(kwh);
}
void PutInIndex(const KeyWithHash &kwh, IdType id, size_t offset) {
if (!contains(kwh))
return;
EdgeInfoStorage<IdType> &entry = this->get_raw_value_reference(kwh);
entry.emplace_back(id, (unsigned int)offset);
}
const EdgeInfoStorage<IdType> get(const KMer& kmer) const {
auto kwh = base::ConstructKWH(kmer);
auto entry = this->get_value(kwh);
return entry;
}
//todo delete if equal seems to work improperly!!!
bool DeleteIfEqual(const KeyWithHash &, IdType) {
VERIFY(false);
return false;
}
};
}
|