mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / include / kernel / NodeBitmask.hpp
blob902e754e05608593ff3c8651eb5b7568415767c3
1 /* Copyright (c) 2003, 2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #ifndef NODE_BITMASK_HPP
17 #define NODE_BITMASK_HPP
19 #include <ndb_limits.h>
20 #include <kernel_types.h>
21 #include <Bitmask.hpp>
23 /**
24 * No of 32 bits words needed to store a node bitmask
25 * containing all the nodes in the system
26 * Both NDB nodes and API, MGM... nodes
28 * Note that this is used in a lot of signals
30 #define _NODE_BITMASK_SIZE 2
32 /**
33 * No of 32 bits words needed to store a node bitmask
34 * containing all the ndb nodes in the system
36 * Note that this is used in a lot of signals
38 #define _NDB_NODE_BITMASK_SIZE 2
40 /**
41 * No of 32 bits word needed to store B bits for N nodes
43 #define NODE_ARRAY_SIZE(N, B) (((N)*(B)+31) >> 5)
45 typedef Bitmask<(unsigned int)_NODE_BITMASK_SIZE> NodeBitmask;
47 typedef Bitmask<(unsigned int)_NDB_NODE_BITMASK_SIZE> NdbNodeBitmask;
49 #define __NBM_SZ ((MAX_NODES >> 5) + ((MAX_NODES & 31) != 0))
50 #define __NNBM_SZ ((MAX_NDB_NODES >> 5) + ((MAX_NDB_NODES & 31) != 0))
52 #if ( __NBM_SZ > _NODE_BITMASK_SIZE)
53 #error "MAX_NODES can not fit into NODE_BITMASK_SIZE"
54 #endif
56 #if ( __NNBM_SZ > _NDB_NODE_BITMASK_SIZE)
57 #error "MAX_NDB_NODES can not fit into NDB_NODE_BITMASK_SIZE"
58 #endif
60 /**
61 * General B Bits operations
63 * Get(x, A[], B)
64 * w = x >> S1
65 * s = (x & S2) << S3
66 * return (A[w] >> s) & S4
68 * Set(x, A[], v, B)
69 * w = x >> S1
70 * s = (x & S2) << S3
71 * m = ~(S4 << s)
72 * t = A[w] & m;
73 * A[w] = t | ((v & S4) << s)
75 * B(Bits) S1 S2 S3 S4
76 * 1 5 31 0 1
77 * 2 4 15 1 3
78 * 4 3 7 2 15
79 * 8 2 3 3 255
80 * 16 1 1 4 65535
82 * S1 = 5 - 2log(B)
83 * S2 = 2^S1 - 1
84 * S3 = 2log(B)
85 * S4 = 2^B - 1
88 #endif