diff --git a/doc/topic/strand.md b/doc/topic/strand.md index 683ac282..00110597 100644 --- a/doc/topic/strand.md +++ b/doc/topic/strand.md @@ -1,61 +1,80 @@ -All tokens in a Humdrum file can be uniquely iterated through with two methods. -The simplest way is to iterate by line and then by field on the line. Here is a -short program that does this to echo out the input Humdrum file contents in the -same format of a standard TSV Humdrum file: +You can uniquely iterate through all tokens in a Humdrum file using +two methods. The simplest one involves iterating first by line and +then by field within each line. Below is a short program that +demonstrates this process by echoing the input Humdrum file contents +in the same format as a standard TSV Humdrum file ```cpp #include "humlib.h" - -HumdrumFile infile; -for (int i=0; i 0) { + infile.read(options.getArg(1)); + } else { + infile.read(cin); + } + for (int i=0; istrands. A strand is a -sequence of tokens in a particular spine which does not include -spine splits or merges. The following figure shows an example -Humdrum data stream with individual strands given different -colors. +To iterate through all spines in an different order, the humlib library +introduces the concept of *strands*. A strand is a sequence of +tokens in a particular spine that does not include spine splits or +merges. The following figure shows example Humdrum data +with individual strands highlighted in different colors. ![Strand example](strand.svg) + Each spine consists of a primary strand which is continuous throughout the total length of the spine. When a spine splits into sub-spines, a new strand starts at the beginning of the right-side branch of the split, while the previous strand continues along the left-side branch. -The strand segments can be used to iterate through all -tokens in the file (excluding non-spine lines, which -are global comments and reference records). A one dimensional -iteration is illustrated in the following code: +The strand segments can be used to iterate through all tokens in +the file (excluding non-spine lines, which are global comments, +reference records and empty lines). A one dimensional iteration +through all tokens is illustrated in the following code: ```cpp + Humdrum infile; HumdrumToken* tok; for (int i=0; iisStrandEnd()) { - cout << *tok << endl; + cout << tok << endl; tok->getNextToken(); } } + ``` The above illustration contains seven 1D strands, so the above code