<commit_before>/*Copyright 2011 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef GUTIL_GLOBALS_H
#define GUTIL_GLOBALS_H

/** \file Global definitions that anyone can use. */

#if (defined(QT_DEBUG) || defined(DEBUG)) && !defined(GUTIL_DEBUG)
    /** Switch on debug features when building in debug mode. */
    #define GUTIL_DEBUG
#endif


#ifdef GUTIL_DEBUG
    #include <iostream>
    /** Special output method for debug mode. */
    #define GDEBUG(x)       std::cout << x
#else
    /** Special output method for debug mode. */
    #define GDEBUG(x)
#endif


/** The GUtil version.  This is always updated after every release.

    See DataObjects/version.h for a useful class for manipulating version strings,
    and for an explanation of the version system used by GUtil.
*/
#define GUTIL_VERSION       "0.0.0"


/** An 8 bit integer*/
#define GINT8   char

/** An 8 bit unsigned integer*/
#define GUINT8   unsigned char

/** A 16 bit integer. */
#define GINT16  short

/** A 16 bit unsigned integer. */
#define GUINT16  unsigned short

/** A 32 bit integer. */
#define GINT32  int

/** A 32 bit unsigned integer. */
#define GUINT32 unsigned int

/** A 64 bit integer. */
#define GINT64  long long

/** A 64 bit unsigned integer. */
#define GUINT64 unsigned long long




// Here are some useful functions

/** Absolute value function.  Use as an alternate to qAbs(). */
template <class T> inline T gAbs(const T &v){ return v < 0 ? -v : v; }

/** Minimum value function.  Use as an alternate to qMin. */
template <class T> inline T gMin(const T &one, const T &two){
    return one < two ? one : two;
}

/** Maximum value function.  Use as an alternate to qMax(). */
template <class T> inline T gMax(const T &one, const T &two){
    return one < two ? two : one;
}



/** Returns the most significant set bit of a 32 bit number in the minimum number of instructions.
    \note O(1).  This is computed in 7 cpu instructions on average.
*/
extern "C" int MSB32(GUINT32);

/** Returns the most significant set bit of a 64 bit number in the minimum number of instructions.
    \note O(1).  This is computed in 9 cpu instructions on average.
*/
extern "C" int MSB64(GUINT64);

/** This is a lookup table which allows us to find the MSB in constant time (and very few instructions). */
extern const char MSB_LOOKUP_TABLE[256];


/** Generates a 32-bit bitmask where the first n bits are set to 1.
    \note O(1), takes 4 instructions to generate.
*/
inline static GUINT32 GEN_BITMASK_32(int n)
{
    if(--n < 0) return 0;
    GINT32 ret(0x80000000);
    return static_cast<GUINT32>(ret >> n);
}



/** Truncate the left n bits of the word. */
inline static GUINT32 &TRUNCATE_LEFT_32(GUINT32 &w, int n)
{
    return w = ((w << n) >> n);
}


/** Some global enumerations that you can use for consistency
    accross libraries and applications.  It's just for convention's sake.
 */
enum GUtilTimeFormatEnum
{
    GUtilFormat12Hours = 0,
    GUtilFormat24Hours = 1
};


// Some useful time constants

/** The number of seconds in a minute. */
#define MINUTE_IN_SECONDS       60

/** The number of seconds in an hour. */
#define HOUR_IN_SECONDS         60 * 60

/** The number of seconds in a day. */<commit_msg>Improved the absolute value function and tweaked the bitmask generation function<commit_after>/*Copyright 2011 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef GUTIL_GLOBALS_H
#define GUTIL_GLOBALS_H

/** \file Global definitions that anyone can use. */

#if (defined(QT_DEBUG) || defined(DEBUG)) && !defined(GUTIL_DEBUG)
    /** Switch on debug features when building in debug mode. */
    #define GUTIL_DEBUG
#endif


#ifdef GUTIL_DEBUG
    #include <iostream>
    /** Special output method for debug mode. */
    #define GDEBUG(x)       std::cout << x
#else
    /** Special output method for debug mode. */
    #define GDEBUG(x)
#endif


/** The GUtil version.  This is always updated after every release.

    See DataObjects/version.h for a useful class for manipulating version strings,
    and for an explanation of the version system used by GUtil.
*/
#define GUTIL_VERSION       "0.0.0"


/** An 8 bit integer*/
#define GINT8   char

/** An 8 bit unsigned integer*/
#define GUINT8   unsigned char

/** A 16 bit integer. */
#define GINT16  short

/** A 16 bit unsigned integer. */
#define GUINT16  unsigned short

/** A 32 bit integer. */
#define GINT32  int

/** A 32 bit unsigned integer. */
#define GUINT32 unsigned int

/** A 64 bit integer. */
#define GINT64  long long

/** A 64 bit unsigned integer. */
#define GUINT64 unsigned long long




// Here are some useful functions

/** Absolute value function which doesn't use branching.  Use as an alternate to qAbs(). */
template <class T> inline T gAbs(const T &v){
    const int mask( v >> (sizeof(int) * 8 - 1) );
    return (v + mask) ^ mask;
}

/** Minimum value function.  Use as an alternate to qMin. */
template <class T> inline T gMin(const T &one, const T &two){
    return one < two ? one : two;
}

/** Maximum value function.  Use as an alternate to qMax(). */
template <class T> inline T gMax(const T &one, const T &two){
    return one < two ? two : one;
}



/** Returns the most significant set bit of a 32 bit number in the minimum number of instructions.
    \note O(1).  This is computed in 7 cpu instructions on average.
*/
extern "C" int MSB32(GUINT32);

/** Returns the most significant set bit of a 64 bit number in the minimum number of instructions.
    \note O(1).  This is computed in 9 cpu instructions on average.
*/
extern "C" int MSB64(GUINT64);

/** This is a lookup table which allows us to find the MSB in constant time (and very few instructions). */
extern const char MSB_LOOKUP_TABLE[256];


/** Generates a 32-bit bitmask where all the bits up to index i are set to 1, starting from the least significant bit.
    \note O(1), takes 3 instructions to generate.
*/
inline static GUINT32 GEN_BITMASK_32(int n)
{
    return ~(GINT32(0x80000000) >> (30 - n));
}



/** Truncate the left n bits of the word. */
inline static GUINT32 &TRUNCATE_LEFT_32(GUINT32 &w, int n)
{
    return w = ((w << n) >> n);
}


/** Some global enumerations that you can use for consistency
    accross libraries and applications.  It's just for convention's sake.
 */
enum GUtilTimeFormatEnum
{
    GUtilFormat12Hours = 0,
    GUtilFormat24Hours = 1
};


// Some useful time constants

/** The number of seconds in a minute. */
#define MINUTE_IN_SECONDS       60

/** The number of seconds in an hour. */
#define HOUR_IN_SECONDS         60 * 60

/** The number of seconds in a day. */
{'fraction_non_alphanumeric': 0.09716706380725443, 'fraction_numerical': 0.02660841938046068, 'mean_word_length': 3.2659514398644833, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2703141', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2224, 'n_words': 1036}