<commit_before>/*
    Copyright (C) 2016 <NAME>

    This file is part of FLINT.

    FLINT is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.  See <http://www.gnu.org/licenses/>.
*/

#ifndef HASHMAP_H
#define HASHMAP_H

#include "flint.h"

#define HASHMAP_START_SIZE 1024
#define HASHMAP_START_MASK (HASHMAP_START_SIZE - 1)

/******************************************************************************

   Hashmap types with one word key

******************************************************************************/

typedef struct hashmap1_elem_s
{
   ulong key;
   void * value;
   int in_use;
} hashmap1_elem_s;

typedef struct hashmap1_s
{
   slong alloc;
   slong num_used;
   ulong mask;
   hashmap1_elem_s * data;
} hashmap1_s;

typedef hashmap1_s hashmap1_t[1];

/******************************************************************************

   Hash functions

******************************************************************************/

/* from lookup3.c, by <NAME>, May 2006, Public Domain. */

#define hash_rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))

#define hash_mix(a,b,c) \
{ \
  c ^= b; c -= hash_rot(b, 14); \
  a ^= c; a -= hash_rot(c, 11); \
  b ^= a; b -= hash_rot(a, 25); \
  c ^= b; c -= hash_rot(b, 16); \
  a ^= c; a -= hash_rot(c,  4); \
  b ^= a; b -= hash_rot(a, 14); \
  c ^= b; c -= hash_rot(b, 24); \
}

/* End of Public Domain code. */

#if FLINT64

static __inline__
ulong hash_word(ulong val)
{
   int * ptr = (int * ) &val;
   int a = ptr[0], b = ptr[1], c = 0;

   hash_mix(a, b, c);
   
   ptr[0] = b;
   ptr[1] = c;

   return val;
}

#else

static __inline__
ulong hash_word(ulong a)
{
   int b = c = 0;

   hash_mix(a, b, c);
   
   return c;
}

#endif

/******************************************************************************

   Hashmap functions with one word key

******************************************************************************/

FLINT_DLL void hashmap1_init(hashmap1_t h);

FLINT_DLL void hashmap1_init2(hashmap1_t h, slong size);

FLINT_DLL void hashmap1_clear(hashmap1_t h);

static __inline__
ulong hashmap1_hash_key(ulong key, hashmap1_t h)
{
   return hash_word(key) & h->mask;
}

FLINT_DLL slong hashmap1_hash(ulong key, hashmap1_t h);

FLINT_DLL void hashmap1_rehash(hashmap1_t h);
<commit_msg>Fix a problem for some C compilers.<commit_after>/*
    Copyright (C) 2016 <NAME>

    This file is part of FLINT.

    FLINT is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.  See <http://www.gnu.org/licenses/>.
*/

#ifndef HASHMAP_H
#define HASHMAP_H

#include "flint.h"

#define HASHMAP_START_SIZE 1024
#define HASHMAP_START_MASK (HASHMAP_START_SIZE - 1)

/******************************************************************************

   Hashmap types with one word key

******************************************************************************/

typedef struct hashmap1_elem_s
{
   ulong key;
   void * value;
   int in_use;
} hashmap1_elem_s;

typedef struct hashmap1_s
{
   slong alloc;
   slong num_used;
   ulong mask;
   hashmap1_elem_s * data;
} hashmap1_s;

typedef hashmap1_s hashmap1_t[1];

/******************************************************************************

   Hash functions

******************************************************************************/

/* from lookup3.c, by <NAME>, May 2006, Public Domain. */

#define hash_rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))

#define hash_mix(a,b,c) \
{ \
  c ^= b; c -= hash_rot(b, 14); \
  a ^= c; a -= hash_rot(c, 11); \
  b ^= a; b -= hash_rot(a, 25); \
  c ^= b; c -= hash_rot(b, 16); \
  a ^= c; a -= hash_rot(c,  4); \
  b ^= a; b -= hash_rot(a, 14); \
  c ^= b; c -= hash_rot(b, 24); \
}

/* End of Public Domain code. */

#if FLINT64

static __inline__
ulong hash_word(ulong val)
{
   int * ptr = (int * ) &val;
   int a = ptr[0], b = ptr[1], c = 0;

   hash_mix(a, b, c);
   
   ptr[0] = b;
   ptr[1] = c;

   return val;
}

#else

static __inline__
ulong hash_word(ulong a)
{
   int b = 0, c = 0;

   hash_mix(a, b, c);
   
   return c;
}

#endif

/******************************************************************************

   Hashmap functions with one word key

******************************************************************************/

FLINT_DLL void hashmap1_init(hashmap1_t h);

FLINT_DLL void hashmap1_init2(hashmap1_t h, slong size);

FLINT_DLL void hashmap1_clear(hashmap1_t h);

static __inline__
ulong hashmap1_hash_key(ulong key, hashmap1_t h)
{
   return hash_word(key) & h->mask;
}

FLINT_DLL slong hashmap1_hash(ulong key, hashmap1_t h);

FLINT_DLL void hashmap1_rehash(hashmap1_t h);

{'fraction_non_alphanumeric': 0.29445889177835566, 'fraction_numerical': 0.024204840968193638, 'mean_word_length': 3.995004995004995, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6755802', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1705, 'n_words': 491}