<commit_before>#pragma once
#include "akumuli_def.h"
#include "operators/operator.h"

#include <tuple>
#include <vector>
#include <cassert>

namespace Akumuli {

struct TupleOutputUtils {
    /** Get pointer to buffer and return pointer to sample and tuple data */
    static std::tuple<aku_Sample*, double*> cast(u8* dest) {
        aku_Sample* sample = reinterpret_cast<aku_Sample*>(dest);
        double* tuple      = reinterpret_cast<double*>(sample->payload.data);
        return std::make_tuple(sample, tuple);
    }

    static double get_flags(std::vector<StorageEngine::AggregationFunction> const& tup) {
        // Shift will produce power of two (e.g. if tup.size() == 3 then
        // (1 << tup.size) will give us 8, 8-1 is 7 (exactly three lower
        // bits is set)).
        union {
            double d;
            u64 u;
        } bits;
        bits.u = (1ull << tup.size()) - 1;
        // Save number of elements in the bitflags
        bits.u |= tup.size() << 58;
        return bits.d;
    }

    // Returns size of the tuple and bitmap
    static std::tuple<u32, u64> get_size_and_bitmap(double value) {
        union {
            double d;
            u64 u;
        } bits;
        bits.d = value;
        u32 size = static_cast<u32>(bits.u >> 58);
        u32 bitmap = 0x3ffffffffffffff & bits.u;
        return std::make_tuple(size, bitmap);
    }

    static double get(StorageEngine::AggregationResult const& res, StorageEngine::AggregationFunction afunc) {<commit_msg>Fix: Shifting correct sized type<commit_after>#pragma once
#include "akumuli_def.h"
#include "operators/operator.h"

#include <tuple>
#include <vector>
#include <cassert>

namespace Akumuli {

struct TupleOutputUtils {
    /** Get pointer to buffer and return pointer to sample and tuple data */
    static std::tuple<aku_Sample*, double*> cast(u8* dest) {
        aku_Sample* sample = reinterpret_cast<aku_Sample*>(dest);
        double* tuple      = reinterpret_cast<double*>(sample->payload.data);
        return std::make_tuple(sample, tuple);
    }

    static double get_flags(std::vector<StorageEngine::AggregationFunction> const& tup) {
        // Shift will produce power of two (e.g. if tup.size() == 3 then
        // (1 << tup.size) will give us 8, 8-1 is 7 (exactly three lower
        // bits is set)).
        union {
            double d;
            u64 u;
        } bits;
        bits.u = (1ull << tup.size()) - 1;
        // Save number of elements in the bitflags
        bits.u |= (u64)tup.size() << 58;
        return bits.d;
    }

    // Returns size of the tuple and bitmap
    static std::tuple<u32, u64> get_size_and_bitmap(double value) {
        union {
            double d;
            u64 u;
        } bits;
        bits.d = value;
        u32 size = static_cast<u32>(bits.u >> 58);
        u32 bitmap = 0x3ffffffffffffff & bits.u;
        return std::make_tuple(size, bitmap);
    }

    static double get(StorageEngine::AggregationResult const& res, StorageEngine::AggregationFunction afunc) {
{'fraction_non_alphanumeric': 0.11848184818481848, 'fraction_numerical': 0.019801980198019802, 'mean_word_length': 2.448236632536974, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4804164', 'n_tokens_mistral': 971, 'n_tokens_neox': 922, 'n_words': 270}