Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 40d4000
  • /
  • src
  • /
  • vec
  • /
  • int_vector.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:23d657d1bb4251bc1fbc37571f242c28720c0e8d
directory badge
swh:1:dir:f09205d8adb48efd3a61a02cbd11e7d611399762

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
int_vector.cpp
#include <algorithm>
#include <tdc/vec/int_vector.hpp>

using namespace tdc::vec;

IntVectorBuilder::IntVectorBuilder(const size_t width, const size_t capacity) {
    m_vector.resize(capacity, width);
}

uint64_t IntVector::get(const size_t i) const {
    const size_t j = i * m_width;
    const size_t a = j >> 6ULL;                    // left border
    const size_t b = (j + m_width - 1ULL) >> 6ULL; // right border

    // da is the distance of a's relevant bits from the left border
    const size_t da = j & 63ULL;

    // wa is the number of a's relevant bits
    const size_t wa = 64ULL - da;

    // get the wa highest bits from a
    const uint64_t a_hi = m_data[a] >> da;

    // get b (its high bits will be masked away below)
    // NOTE: we could save this step if we knew a == b,
    //       but the branch caused by checking that is too expensive
    const uint64_t b_lo = m_data[b];

    // combine
    return ((b_lo << wa) | a_hi) & m_mask;
}

void IntVector::set(const size_t i, const uint64_t v_) {
    const uint64_t v = v_ & m_mask; // make sure it fits...
    
    const size_t j = i * m_width;
    const size_t a = j >> 6ULL;       // left border
    const size_t b = (j + m_width - 1ULL) >> 6ULL; // right border
    if(a < b) {
        // the bits are the suffix of m_data[a] and prefix of m_data[b]
        const size_t da = j & 63ULL;
        const size_t wa = 64ULL - da;
        const size_t wb = m_width - wa;
        const size_t db = 64ULL - wb;

        // combine the da lowest bits from a and the wa lowest bits of v
        const uint64_t a_lo = m_data[a] & math::bit_mask<uint64_t>(da);
        const uint64_t v_lo = v & math::bit_mask<uint64_t>(wa);
        m_data[a] = (v_lo << da) | a_lo;

        // combine the db highest bits of b and the wb highest bits of v
        const uint64_t b_hi = m_data[b] >> wb;
        const uint64_t v_hi = v >> wa;
        m_data[b] = (b_hi << wb) | v_hi;
    } else {
        const size_t dl = j & 63ULL;
        const uint64_t xa = m_data[a];
        const uint64_t mask_lo = math::bit_mask<uint64_t>(dl);
        const uint64_t mask_hi = ~mask_lo << m_width;
        
        m_data[a] = (xa & mask_lo) | (v << dl) | (xa & mask_hi);
    }
}

void IntVector::resize(const size_t size, const size_t width) {
    IntVector new_iv(size, width, size * width >= m_size * m_width); // no initialization needed if new size is smaller
    
    const size_t num_to_copy = std::min(size, m_size);
    for(size_t i = 0; i < num_to_copy; i++) {
        new_iv.set(i, get(i));
    }
    *this = std::move(new_iv);
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API