<commit_before>/*
 * Copyright 2013 by <NAME>
 *
 * See the file COPYING for the licence associated with this software.
 *
 * Author(s):
 *   <NAME>, July 2013
 */

#include <cassert>
#include <cstring>
#include <stdexcept>

#include "var.h"
#include "varheap.h"

#ifdef VARBOSE
# include <cstdlib>
# define VDEBUG(a) a
#else
# define VDEBUG(a)
#endif


using namespace libvar;


/*
 * Template specialisations (before any get used)
 *
 * These can be used to get the actual storage.  C++ doesn't allow
 * overloading on return type, so the return type must be specified.
 */
template<> char* varheap::ptr<char>(int iIndex) const {
    return mView ? mView->ptr<char>(iIndex + mData.ip[0]) : mData.cp + iIndex;
}
template<> int* varheap::ptr<int>(int iIndex) const {
    return mView ? mView->ptr<int>(iIndex + mData.ip[0]) : mData.ip + iIndex;
}
template<> long* varheap::ptr<long>(int iIndex) const {
    return mView ? mView->ptr<long>(iIndex + mData.ip[0]) : mData.lp + iIndex;
}
template<> float* varheap::ptr<float>(int iIndex) const {
    return mView ? mView->ptr<float>(iIndex + mData.ip[0]) : mData.fp + iIndex;
}
template<> double* varheap::ptr<double>(int iIndex) const {
    return mView ? mView->ptr<double>(iIndex + mData.ip[0]) : mData.dp + iIndex;
}
template<> cfloat* varheap::ptr<cfloat>(int iIndex) const {
    return mView
        ? mView->ptr<cfloat>(iIndex + mData.ip[0]) : mData.cfp + iIndex;
}
template<> cdouble* varheap::ptr<cdouble>(int iIndex) const {
    return mView
        ? mView->ptr<cdouble>(iIndex + mData.ip[0]) : mData.cdp + iIndex;
}
template<> var* varheap::ptr<var>(int iIndex) const {
    return mView ? mView->ptr<var>(iIndex + mData.ip[0]) : mData.vp + iIndex;
}
template<> pair* varheap::ptr<pair>(int iIndex) const {
    return mView ? mView->ptr<pair>(iIndex + mData.ip[0]) : mData.pp + iIndex;
}


int sizeOf(ind iType)
{
    switch (iType)
    {
    case TYPE_CHAR: return sizeof(char);
    case TYPE_INT: return sizeof(int);
    case TYPE_LONG: return sizeof(long);
    case TYPE_FLOAT: return sizeof(float);
    case TYPE_DOUBLE: return sizeof(double);
    case TYPE_VAR: return sizeof(var);
    case TYPE_PAIR: return sizeof(pair);
    default:
        throw std::runtime_error("sizeOf(): Unknown type");
    }
}

/**
 * Default constructor; should all be zero.
 */
varheap::varheap()
{
    mData.vp = 0;
    mSize = 0;<commit_msg>Add couple of missing size types<commit_after>/*
 * Copyright 2013 by <NAME>
 *
 * See the file COPYING for the licence associated with this software.
 *
 * Author(s):
 *   <NAME>, July 2013
 */

#include <cassert>
#include <cstring>
#include <stdexcept>

#include "var.h"
#include "varheap.h"

#ifdef VARBOSE
# include <cstdlib>
# define VDEBUG(a) a
#else
# define VDEBUG(a)
#endif


using namespace libvar;


/*
 * Template specialisations (before any get used)
 *
 * These can be used to get the actual storage.  C++ doesn't allow
 * overloading on return type, so the return type must be specified.
 */
template<> char* varheap::ptr<char>(int iIndex) const {
    return mView ? mView->ptr<char>(iIndex + mData.ip[0]) : mData.cp + iIndex;
}
template<> int* varheap::ptr<int>(int iIndex) const {
    return mView ? mView->ptr<int>(iIndex + mData.ip[0]) : mData.ip + iIndex;
}
template<> long* varheap::ptr<long>(int iIndex) const {
    return mView ? mView->ptr<long>(iIndex + mData.ip[0]) : mData.lp + iIndex;
}
template<> float* varheap::ptr<float>(int iIndex) const {
    return mView ? mView->ptr<float>(iIndex + mData.ip[0]) : mData.fp + iIndex;
}
template<> double* varheap::ptr<double>(int iIndex) const {
    return mView ? mView->ptr<double>(iIndex + mData.ip[0]) : mData.dp + iIndex;
}
template<> cfloat* varheap::ptr<cfloat>(int iIndex) const {
    return mView
        ? mView->ptr<cfloat>(iIndex + mData.ip[0]) : mData.cfp + iIndex;
}
template<> cdouble* varheap::ptr<cdouble>(int iIndex) const {
    return mView
        ? mView->ptr<cdouble>(iIndex + mData.ip[0]) : mData.cdp + iIndex;
}
template<> var* varheap::ptr<var>(int iIndex) const {
    return mView ? mView->ptr<var>(iIndex + mData.ip[0]) : mData.vp + iIndex;
}
template<> pair* varheap::ptr<pair>(int iIndex) const {
    return mView ? mView->ptr<pair>(iIndex + mData.ip[0]) : mData.pp + iIndex;
}


int sizeOf(ind iType)
{
    switch (iType)
    {
    case TYPE_CHAR: return sizeof(char);
    case TYPE_INT: return sizeof(int);
    case TYPE_LONG: return sizeof(long);
    case TYPE_FLOAT: return sizeof(float);
    case TYPE_DOUBLE: return sizeof(double);
    case TYPE_CFLOAT: return sizeof(cfloat);
    case TYPE_CDOUBLE: return sizeof(cdouble);
    case TYPE_VAR: return sizeof(var);
    case TYPE_PAIR: return sizeof(pair);
    default:
        throw std::runtime_error("sizeOf(): Unknown type");
    }
}

/**
 * Default constructor; should all be zero.
 */
varheap::varheap()
{
    mData.vp = 0;
    mSize = 0;
{'fraction_non_alphanumeric': 0.15208034433285508, 'fraction_numerical': 0.007788481246156999, 'mean_word_length': 3.979591836734694, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1912397', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1714, 'n_words': 454}