void table<RecordType>::insert(const RecordType& entry) // Library facilities used: cassert { bool already_present; // True if entry.key is already in the table size_t index; // data[index] is location for the new entry assert(entry.key >= 0); // Set index so that data[index] is the spot to place the new entry. find_index(entry.key, already_present, index); // If the key wasn't already there, then find the location for the new entry. if (!already_present) { assert(size( ) < CAPACITY); index = hash(entry.key); while (!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; }
int paralign_score(buffer_t* buffer, const submat_t<score_t> submat, const score_t gap_open, const score_t gap_extend, const seq_t seq, const seq_t* refs, const int n_refs, alignment_t** alignments) { if (n_refs == 0) return 0; else if (n_refs < 0) return 1; // allocate working space if (expand_buffer(buffer, sizeof(vec_t) * (seq.len + 1) * 2 + sizeof(vec_t) * submat.size + sizeof(uint8_t) * seq.len)) { return 1; } // NOTE: colE[0] is not used vec_t* colE = (vec_t*)buffer->data; vec_t* colH = colE + seq.len + 1; vec_t* prof = colH + seq.len + 1; uint8_t* useq = reinterpret_cast<uint8_t*>(prof + submat.size); // unpack sequence for (size_t i = 0; i < seq.len; i++) useq[i] = seq[i]; // initialize slots which hold the reference sequences const int n_max_par = sizeof(vec_t) / sizeof(score_t); std::array<slot_t,n_max_par> slots; slots.fill(empty_slot); int next_ref = 0; // outer loop along refs while (true) { // initialize the slots and the column vectors for (int k = 0; k < n_max_par; k++) { slot_t &slot = slots[k]; if (slot != empty_slot) { slot.pos++; if (slot.pos < refs[slot.id].len) continue; else (*alignments[slot.id]).score = simd_extract<score_t>(colH[seq.len], k); } // find the next non-empty sequences if any bool found = false; while (next_ref < n_refs && !found) { // reset E and H colH[0] = simd_insert<score_t>(colH[0], 0, k); for (int i = 1; i <= seq.len; i++) { score_t h = affine_gap_score(i, gap_open, gap_extend); colH[i] = simd_insert(colH[i], h, k); colE[i] = simd_insert(colE[i], static_cast<score_t>(h - (gap_open + gap_extend)), k); } seq_t ref = refs[next_ref]; if (ref.len == 0) { (*alignments[next_ref++]).score = simd_extract<score_t>(colH[seq.len], k); } else { slot.id = next_ref++; slot.pos = 0; found = true; } } if (!found) slots[k] = empty_slot; } // check if there are remaining slots if (is_vacant(slots)) break; // fill the temporary profile fill_profile(refs, slots, submat, prof); // inner loop along seq // TODO: detect saturation loop(useq, seq.len, prof, slots, gap_open, gap_extend, colE, colH); } return 0; }