Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
Thopic committed Sep 7, 2024
1 parent de215f2 commit 0b19f3c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ciso646>
#include "trie_container.hpp"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand Down
24 changes: 13 additions & 11 deletions src/trie.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef TRIE_HPP
#define TRIE_HPP

#include <ciso646>
#include "utils.hpp"



/* Class implementing a digital trie, that contain a number
std::size_t in each occupied node.
Nodes have to be occupied.
Expand All @@ -13,11 +15,11 @@ class Trie{
private:

// all the childrens of a trie are trie
std::vector<Trie*> cs;
std::vector<Trie*> cs;
// if the node is occupied (full = True)
bool full;
// if the node is occupied contains the number associated with it
std::size_t obj;
std::size_t obj;
// number of character in the alphabet
std::size_t alph_size;

Expand All @@ -26,7 +28,7 @@ class Trie{
Trie(std::size_t alph_size) : full(false), obj(0), alph_size(alph_size) {
cs = std::vector<Trie*>(alph_size, NULL);
}

~Trie(){
for(auto n: cs)
delete n;
Expand All @@ -42,7 +44,7 @@ class Trie{
}
return size;
}

// insert one sequence into the Trie, overwrite if already here
void insert(seq::iterator b, seq::iterator e, std::size_t o){
if(b == e){
Expand All @@ -54,7 +56,7 @@ class Trie{
cs[*b] = new Trie(alph_size);
cs[*b]->insert(std::next(b),e,o);
}
}
}

// remove an amino sequence from the Trie
void remove(seq::iterator b, seq::iterator e){
Expand All @@ -63,7 +65,7 @@ class Trie{
else{
if(cs[*b] != NULL){ // if not the word is not in the Trie
cs[*b]->remove(std::next(b), e);
if(cs[*b]->is_leaf() and not cs[*b]->full){
if((cs[*b]->is_leaf()) and (not cs[*b]->full)){
delete cs[*b];
cs[*b] = NULL;
}
Expand All @@ -77,7 +79,7 @@ class Trie{
if(cs[*b] == NULL)
return false;
else
return cs[*b]->contain(std::next(b), e);
return cs[*b]->contain(std::next(b), e);
}

bool is_leaf(){
Expand All @@ -87,7 +89,7 @@ class Trie{
}
return true;
}

bool empty(){
for(std::size_t ii=0; ii < alph_size; ++ii){
if(cs[ii] != NULL)
Expand All @@ -107,8 +109,8 @@ class Trie{
if(cs[ii] != NULL)
cs[ii]->print(" " + tab + alphabet[ii], alphabet);
}
}
}

// return the first dna sequence found in the tree and its content
void next(seq& d, std::size_t& content) const{
if(not full){ // if we don't find one at the current node
Expand All @@ -121,7 +123,7 @@ class Trie{
}
}
else{ // if we found an occupied node, we stop
content = obj;
content = obj;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/trie_container.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TRIE_CONT
#define TRIE_CONT

#include <ciso646>
#include "trie.hpp"
#include "utils.hpp"

Expand All @@ -16,7 +17,7 @@ class TrieContainer{
const str alphabet;
// Also contain the sequences, for easy back-and-forth

vecs seqs;
vecs seqs;

seq string_to_seqence(const str& s) {
seq sequence = seq(s.size());
Expand Down Expand Up @@ -50,7 +51,7 @@ class TrieContainer{
void insert(const str& str_seq){
seq d = string_to_seqence(str_seq);
seqs.push_back(str_seq);
tr.insert(d.begin(), d.end(), seqs.size()-1);
tr.insert(d.begin(), d.end(), seqs.size()-1);
}

void insert_list(const vecs& str_seqs){
Expand Down
3 changes: 2 additions & 1 deletion src/try.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ciso646>
#include "trie_container.hpp"


Expand Down Expand Up @@ -36,4 +37,4 @@ int main(){


return 0;
}
}
1 change: 1 addition & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define UTILS


#include <ciso646>
#include <chrono>
#include <string>
#include <fstream>
Expand Down

0 comments on commit 0b19f3c

Please sign in to comment.