commit 3023710e83a51c21ff03df416b1c3296ce18046c
parent 98f243010f0d674d7f6e77c880d9255ac802d7a2
Author: Adam Malone <[email protected]>
Date: Wed, 14 Nov 2018 17:31:32 -0600
add interleaveExpand in dtPulse. Expands a vector of strings by interleaving successive characters
Diffstat:
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp
@@ -8,7 +8,7 @@ bool is_digits(const std::string &str)
}
std::vector<int> parseStringAsTimes(std::string input, std::string lookup) {
-// "113" -> {1,1,3}
+// "113" -> {1,1,1,0,0}
return parseEntireString(input,lookup,0);
}
@@ -18,7 +18,6 @@ std::vector<int> parseStringAsValues(std::string input, std::string lookup) {
}
std::vector<int> parseEntireString(std::string input,std::string lookup,int type) {
-// "113" -> {1,1,1,0,0}
std::vector<int> absoluteSequence;
absoluteSequence.resize(0);
bool noNumbers = true;
@@ -130,6 +129,33 @@ std::vector<int> parseDt(std::string input, int offset, std::string lookup) {
}
return absoluteSequence;
}
+std::string interleaveExpand(std::vector<std::string> blocks) {
+ std::vector<int> indices;
+ std::vector<int> lengths;
+ int outerIndex = 0;
+ int outerLength = blocks.size();
+ int steps = 0;
+ bool allAtZero = false;
+ std::string output="";
+ for(int i = 0; i < outerLength; i++) {
+ indices.push_back(0);
+ lengths.push_back(blocks[i].length());
+ }
+ while((!allAtZero && steps < 6000 ) || steps == 0) {
+ output+=blocks[outerIndex][indices[outerIndex]];
+ indices[outerIndex]++;
+ indices[outerIndex]%=lengths[outerIndex];
+ outerIndex++;
+ outerIndex%=outerLength;
+ steps++;
+ allAtZero = outerIndex==0;
+
+ for(int i = 0; i < outerLength; i++) {
+ allAtZero &= (indices[i] == 0);
+ }
+ }
+ return output;
+}
std::string atExpand(std::string input, int atnum, std::string lookup) {
std::string output="";
int length = input.length();
diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp
@@ -12,6 +12,7 @@ std::vector<int> parseEntireString(std::string input,std::string lookup, int typ
std::vector<int> parseStringAsValues(std::string input,std::string lookup);
std::vector<int> parseStringAsTimes(std::string input,std::string lookup);
void printVector(std::vector <int> intVector);
+std::string interleaveExpand(std::vector<std::string> blocks);
std::string hashExpand(std::string input, int hashnum);
std::string atExpand(std::string input, int atnum, std::string lookup);
std::string countExpand(std::string input, int atnum);