import (
"bufio"
"bytes"
+ "encoding/gob"
"io"
"strings"
"sync"
}
type tileLibrary struct {
- skipOOO bool
- taglib *tagLibrary
- variant [][][blake2b.Size256]byte
+ includeNoCalls bool
+ skipOOO bool
+ taglib *tagLibrary
+ variant [][][blake2b.Size256]byte
// count [][]int
// seq map[[blake2b.Size]byte][]byte
variants int
+ // if non-nil, write out any tile variants added while tiling
+ encoder *gob.Encoder
mtx sync.Mutex
}
// Return a tileLibRef for a tile with the given tag and sequence,
// adding the sequence to the library if needed.
func (tilelib *tileLibrary) getRef(tag tagID, seq []byte) tileLibRef {
- for _, b := range seq {
- if b != 'a' && b != 'c' && b != 'g' && b != 't' {
- // return "tile not found" if seq has any
- // no-calls
- return tileLibRef{tag: tag}
+ if !tilelib.includeNoCalls {
+ for _, b := range seq {
+ if b != 'a' && b != 'c' && b != 'g' && b != 't' {
+ // return "tile not found" if seq has any
+ // no-calls
+ return tileLibRef{tag: tag}
+ }
}
}
tilelib.mtx.Lock()
- defer tilelib.mtx.Unlock()
// if tilelib.seq == nil {
// tilelib.seq = map[[blake2b.Size]byte][]byte{}
// }
seqhash := blake2b.Sum256(seq)
for i, varhash := range tilelib.variant[tag] {
if varhash == seqhash {
+ tilelib.mtx.Unlock()
return tileLibRef{tag: tag, variant: tileVariantID(i + 1)}
}
}
tilelib.variants++
tilelib.variant[tag] = append(tilelib.variant[tag], seqhash)
// tilelib.seq[seqhash] = append([]byte(nil), seq...)
- return tileLibRef{tag: tag, variant: tileVariantID(len(tilelib.variant[tag]))}
+ ret := tileLibRef{tag: tag, variant: tileVariantID(len(tilelib.variant[tag]))}
+ tilelib.mtx.Unlock()
+
+ if tilelib.encoder != nil {
+ tilelib.encoder.Encode(LibraryEntry{
+ TileVariants: []TileVariant{{
+ Tag: tag,
+ Blake2b: seqhash,
+ Sequence: seq,
+ }},
+ })
+ }
+ return ret
}