File: Pool.h

package info (click to toggle)
mapsembler2 2.2.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,080 kB
  • ctags: 9,676
  • sloc: cpp: 51,021; ansic: 13,465; sh: 460; makefile: 409; asm: 271; python: 28
file content (92 lines) | stat: -rw-r--r-- 1,627 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
//  Pool.h
//  memory pool for hashtable to avoid mallocs
//
//  Created by Guillaume Rizk on 24/11/11.
//

#ifndef compress_Pool_h
#define compress_Pool_h
#include <stdlib.h>
#include <algorithm> // for max/min

#ifdef _ttmath
#include "ttmath/ttmath.h"
#endif
#ifdef _largeint
#include "LargeInt.h"
#endif


typedef unsigned int  cell_ptr_t;

template <typename graine_type>
struct cell
{
    graine_type graine;
    cell_ptr_t  suiv; 
    int val; 
};

#define  TAI_POOL 4194304 //16777216//4194304 // 2^22  16 M cells *16 o    blocs de 256 Mo
#define  N_POOL   1024 //256//1024 //  2^10     soit 4 G cells max 
/**
 * \class Pool, 
 * \brief Cette class dÈfinit une pool memoire pour allocation rapide de la table de hachage utilisee quand seed >14
 */

template <typename graine_type>
class Pool{
public:
	
	/**
	 * table de cell, pour usage courant, 
	 */
	cell<graine_type> * pool_courante;
	/**
	 * stockage de tous les pointeurs  pool
	 */
	cell<graine_type> ** tab_pool;
	/**
	 *  nombre de piscines remplies
	 */
	unsigned int n_pools;

	/**
	 *  niveau de remplissage de la piscine courante 
	 */
	unsigned int n_cells;
    
    
    
	/**
	 * Constructeur par dÈfaut
	 */
	Pool();
	
	/**
	 * alloue une cellule dans la piscine
	 */
	cell<graine_type> *  allocate_cell_in_pool();

    //  allocate cell, return internal pointer type ( 32bits)
    cell_ptr_t  allocate_cell();

      cell<graine_type> *  internal_ptr_to_cell_pointer(cell_ptr_t internal_ptr);

    
	/**
	 * vide toutes piscines
	 * (garde juste une pool vide)
	 */
	void  empty_all();
    
	/**
	 * Destructeur
	 */
	~Pool();
    
};


#endif