+ /**
+ * Create and array of reordered sequences in order first from tmp that are
+ * present in seqList already, then, after that, any remaining sequences in
+ * seqList not in tmp. Any sequences in tmp that are not in seqList already
+ * are discarded.
+ *
+ * @param seqList
+ * thread safe collection of sequences originally in the alignment
+ * @param tmp
+ * thread safe collection of sequences or subsequences possibly in
+ * seqList
+ *
+ * @return intersect(tmp,seqList)+intersect(complement(tmp),seqList)
+ */
+ private static SequenceI[] vectorSubsetToArray(List<SequenceI> seqList,
+ List<SequenceI> tmp)
+ {
+ ArrayList<SequenceI> seqs = new ArrayList<>();
+ int n = seqList.size();
+ BitSet bs = new BitSet(n);
+ bs.set(0, n);
+ for (int i = 0, nt = tmp.size(); i < nt; i++)
+ {
+ SequenceI sq = tmp.get(i);
+ int idx = seqList.indexOf(sq);
+ if (idx >= 0 && bs.get(idx))
+ {
+ seqs.add(sq);
+ bs.clear(idx);
+ }
+ }
+
+ for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1))
+ {
+ seqs.add(seqList.get(i));
+ }
+
+ return seqs.toArray(new SequenceI[seqs.size()]);
+ }