Exemplo n.º 1
0
/***********************************************************************//**
 * @brief Set number of column elements for specific row
 *
 * @param[in] row Row index.
 * @param[in] elements Number of elements in @p row.
 *
 * @exception GException::out_of_range
 *            Invalid row index specified.
 * @exception GException::invalid_argument
 *            Invalid number of elements specified.
 *
 * Sets the number of elements in column for a specific @p row.
 ***************************************************************************/
void GFitsTableCol::elements(const int& row, const int& elements)
{
    // Check row value
    if (row < 0 || row >= length()) {
        throw GException::out_of_range(G_ELEMENTS1, "Row index", row, length());
    }

    // Check that elements is non-negative
    if (elements < 0) {
        std::string msg = "Number of elements " + gammalib::str(elements) +
                          " can not be negative.\nPlease specify a"
                          " non-negative number of elements.";
        throw GException::invalid_argument(G_ELEMENTS1, msg);
    }

    // First handle the case of a variable-length column
    if (is_variable()) {

        // Determine number of elements to add or to remove
        int difference = elements - (m_rowstart[row+1] - m_rowstart[row]);

        // If difference is positive, then add elements at the end of
        // the vector. This is done using resize_data() which will insert
        // "difference" elements at the index specified as first argument
        if (difference > 0) {
            resize_data(m_rowstart[row+1], difference);
        }

        // ... else if difference is negative then remove elements from
        // the end of the array. This is done using resize_data() which
        // will remove "difference" element from the index on specified as
        // first argument
        else if (difference < 0) {
            resize_data(m_rowstart[row+1]+difference, difference);
        }

        // Update row start indices
        for (int i = row + 1; i <= length(); ++i) {
            m_rowstart[i] += difference;
        }

        // Update maximum column length
        m_varlen = 0;
        for (int i = 0; i < length(); ++i) {
            int len = m_rowstart[row+1] - m_rowstart[row];
            if (len > m_varlen) {
                m_varlen = len;
            }
        }
        
    } // endif: we had a variable-length column

    // Return
    return;
}
Exemplo n.º 2
0
 void entry_storage::remove_offset(store_offset ofs) {
     m_data_indexer.remove(ofs);
     store_offset last_ofs = after_last_offset() - m_entry_size;
     if(ofs!=last_ofs) {
         SASSERT(ofs+m_entry_size<=last_ofs);
         //we don't want any holes, so we put the last element at the place
         //of the removed one
         m_data_indexer.remove(last_ofs);
         char * base = &m_data.get(0);
         memcpy(base+ofs, base+last_ofs, m_entry_size);
         m_data_indexer.insert(ofs);
     }
     if(has_reserve()) {
         //we already have a reserve, so we need to shrink a little to keep having just one
         resize_data(m_data_size-m_entry_size);
     }
     m_reserve=last_ofs;
 }
Exemplo n.º 3
0
void addPrediction(uint32_t address, bool pred, bool real)
{
    /*
     * Check if we have already seen this branch and if
     * so update the prediction and real bitvector.
     */
    for (size_t i = 0; i < e.pos; i++) {
        if (e.data[i].address == address) {
            data *d = &(e.data[i]);
            
            if (d->size <= d->pos) {
                resize_data(d);
            }
            d->pred[d->pos] = pred ? 1 : 0;
            d->real[d->pos] = real ? 1 : 0;
            d->pos++;
            return;
        }
    }

    /*
     * We have not seen this branch before. See if there is room in the array
     * And add the first entry in the branch.
     */
    if (e.size <= e.pos) {
        resize_elements(&e);
    }

    data *d = &(e.data[e.pos]);

    d->address = address;
    d->pred[d->pos] = pred ? 1 : 0;
    d->real[d->pos] = real ? 1 : 0;
    d->pos++;
    e.pos++;

}