1
/* Copyright (C) 2004, 2006 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
2
16
#include <ndb_global.h>
3
17
#include <ConfigValues.hpp>
204
218
findKey(const Uint32 * values, Uint32 sz, Uint32 key, Uint32 * _pos){
205
Uint32 pos = hash(key, sz);
207
while((values[pos] & KP_MASK) != key && count < sz){
208
pos = nextHash(key, sz, pos, ++count);
211
if((values[pos] & KP_MASK)== key){
221
Uint32 pos = (hi + lo) >> 1;
223
DEBUG printf("findKey(H'%.8x %d)", key, sz);
227
DEBUG ndbout_c(" -> false, 0");
233
Uint32 oldpos = pos + 1;
234
while (pos != oldpos)
236
DEBUG printf(" [ %d %d %d ] ", lo, pos, hi);
239
val = values[2*pos] & KP_MASK;
251
DEBUG ndbout_c(" -> true, %d", pos);
255
pos = (hi + lo) >> 1;
258
DEBUG printf(" pos: %d (key %.8x val: %.8x values[pos]: %x) key>val: %d ",
259
pos, key, val, values[2*pos] & KP_MASK,
262
pos += (key > val) ? 1 : 0;
265
DEBUG ndbout_c(" -> false, %d", pos);
220
hash(Uint32 key, Uint32 size){
221
Uint32 tmp = (key >> 16) ^ (key & 0xFFFF);
222
return (((tmp << 16) | tmp) % size) << 1;
227
nextHash(Uint32 key, Uint32 size, Uint32 pos, Uint32 count){
228
Uint32 p = (pos >> 1);
229
if((key % size) != 0)
233
return (p % size) << 1;
238
directory(Uint32 sz){
239
const Uint32 _input = sz;
246
for(Uint32 n = 3; n*n <= sz; n += 2){
254
DEBUG printf("directory %d -> %d\n", _input, sz);
258
270
ConfigValuesFactory::ConfigValuesFactory(Uint32 keys, Uint32 data){
259
271
m_sectionCounter = (1 << KP_SECTION_SHIFT);
260
m_freeKeys = directory(keys);
261
273
m_freeData = (data + 7) & ~7;
262
274
m_currentSection = 0;
263
275
m_cfg = create(m_freeKeys, m_freeData);
331
DEBUG printf("[ fk fd ] : [ %d %d ]", m_freeKeys, m_freeData);
319
333
m_freeKeys = (m_freeKeys >= fk ? m_cfg->m_size : fk + m_cfg->m_size);
320
334
m_freeData = (m_freeData >= fs ? m_cfg->m_dataSize : fs + m_cfg->m_dataSize);
321
m_freeKeys = directory(m_freeKeys);
322
335
m_freeData = (m_freeData + 7) & ~7;
337
DEBUG ndbout_c(" [ %d %d ]", m_freeKeys, m_freeData);
324
339
ConfigValues * m_tmp = m_cfg;
325
340
m_cfg = create(m_freeKeys, m_freeData);
337
352
m_freeKeys = m_cfg->m_size - m_freeKeys;
338
353
m_freeData = m_cfg->m_dataSize - m_freeData;
339
m_freeKeys = directory(m_freeKeys);
340
354
m_freeData = (m_freeData + 7) & ~7;
342
356
ConfigValues * m_tmp = m_cfg;
417
431
const Uint32 tmp = entry.m_key | m_currentSection;
418
const Uint32 sz = m_cfg->m_size;
419
Uint32 pos = hash(tmp, sz);
421
Uint32 val = m_cfg->m_values[pos];
423
while((val & KP_MASK) != tmp && val != CFV_KEY_FREE && count < sz){
424
pos = nextHash(tmp, sz, pos, ++count);
425
val = m_cfg->m_values[pos];
428
if((val & KP_MASK) == tmp){
432
const Uint32 sz = m_cfg->m_size - m_freeKeys;
435
if (findKey(m_cfg->m_values, sz, tmp, &pos))
429
437
DEBUG ndbout_c("key %x already found at pos: %d", tmp, pos);
436
Uint32 val = m_cfg->m_values[pos];
438
printf("key: %d, (key %% size): %d\n", entry.m_key, (entry.m_key % sz));
439
printf("pos: %d", pos);
440
while((val & KP_MASK) != tmp && val != CFV_KEY_FREE && count < sz){
441
pos = nextHash(tmp, sz, pos, ++count);
442
val = m_cfg->m_values[pos];
444
for (Uint32 i = 0; i<sz; i++)
446
Uint32 val = m_cfg->m_values[2*i] & KP_MASK;
447
ndbout_c("%.8x", val);
452
assert(pos < (sz << 1));
455
DEBUG ndbout_c("pos: %d sz: %d", pos, sz);
456
memmove(m_cfg->m_values + pos + 2, m_cfg->m_values + pos,
454
461
Uint32 key = tmp;
455
462
key |= (entry.m_type << KP_TYPE_SHIFT);
456
463
m_cfg->m_values[pos] = key;
468
for (Uint32 i = 0; i<=sz; i++)
470
Uint32 val = m_cfg->m_values[2*i] & KP_MASK;
471
ndbout_c("%.8x", val);
457
477
switch(entry.m_type){
458
478
case ConfigValues::IntType:
459
479
case ConfigValues::SectionType:
460
480
m_cfg->m_values[pos+1] = entry.m_int;
462
482
DEBUG printf("Putting at: %d(%d) (loop = %d) key: %d value: %d\n",
464
484
(key >> KP_KEYVAL_SHIFT) & KP_KEYVAL_MASK,
666
const char * end = src + len - 4;
667
src += sizeof(Magic);
688
const char * save = src;
693
while(end - src > 4){
694
Uint32 tmp = ntohl(* (const Uint32 *)src); src += 4;
696
switch(::getTypeOf(tmp)){
697
case ConfigValues::IntType:
698
case ConfigValues::SectionType:
701
case ConfigValues::Int64Type:
705
case ConfigValues::StringType:{
706
Uint32 s_len = ntohl(* (const Uint32 *)src);
707
src += 4 + mod4(s_len);
708
data += sizeof(char*);
669
719
ConfigValues::Entry entry;
670
720
while(end - src > 4){
671
721
Uint32 tmp = ntohl(* (const Uint32 *)src); src += 4;