1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1999
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
60
#include "morkAtomMap.h"
68
#include "morkIntMap.h"
75
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
77
// ````` ````` ````` ````` `````
78
// { ===== begin morkNode interface =====
80
/*public virtual*/ void
81
morkAtomAidMap::CloseMorkNode(morkEnv* ev) // CloseAtomAidMap() only if open
83
if ( this->IsOpenNode() )
86
this->CloseAtomAidMap(ev);
92
morkAtomAidMap::~morkAtomAidMap() // assert CloseAtomAidMap() executed earlier
94
MORK_ASSERT(this->IsShutNode());
99
morkAtomAidMap::morkAtomAidMap(morkEnv* ev, const morkUsage& inUsage,
100
nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
101
#ifdef MORK_ENABLE_PROBE_MAPS
102
: morkProbeMap(ev, inUsage, ioHeap,
103
/*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
104
ioSlotHeap, morkAtomAidMap_kStartSlotCount,
105
/*inZeroIsClearKey*/ morkBool_kTrue)
106
#else /*MORK_ENABLE_PROBE_MAPS*/
107
: morkMap(ev, inUsage, ioHeap,
108
/*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
109
morkAtomAidMap_kStartSlotCount, ioSlotHeap,
110
/*inHoldChanges*/ morkBool_kFalse)
111
#endif /*MORK_ENABLE_PROBE_MAPS*/
114
mNode_Derived = morkDerived_kAtomAidMap;
117
/*public non-poly*/ void
118
morkAtomAidMap::CloseAtomAidMap(morkEnv* ev) // called by CloseMorkNode();
122
if ( this->IsNode() )
124
#ifdef MORK_ENABLE_PROBE_MAPS
125
this->CloseProbeMap(ev);
126
#else /*MORK_ENABLE_PROBE_MAPS*/
128
#endif /*MORK_ENABLE_PROBE_MAPS*/
132
this->NonNodeError(ev);
135
ev->NilPointerError();
138
// } ===== end morkNode methods =====
139
// ````` ````` ````` ````` `````
141
#ifdef MORK_ENABLE_PROBE_MAPS
143
/*virtual*/ mork_test // hit(a,b) implies hash(a) == hash(b)
144
morkAtomAidMap::MapTest(morkEnv* ev, const void* inMapKey,
145
const void* inAppKey) const
148
const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
151
mork_bool hit = key->EqualAid(*(const morkBookAtom**) inAppKey);
152
return ( hit ) ? morkTest_kHit : morkTest_kMiss;
155
return morkTest_kVoid;
158
/*virtual*/ mork_u4 // hit(a,b) implies hash(a) == hash(b)
159
morkAtomAidMap::MapHash(morkEnv* ev, const void* inAppKey) const
161
const morkBookAtom* key = *(const morkBookAtom**) inAppKey;
163
return key->HashAid();
166
ev->NilPointerWarning();
172
morkAtomAidMap::ProbeMapHashMapKey(morkEnv* ev,
173
const void* inMapKey) const
175
const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
177
return key->HashAid();
180
ev->NilPointerWarning();
184
#else /*MORK_ENABLE_PROBE_MAPS*/
185
// { ===== begin morkMap poly interface =====
186
/*virtual*/ mork_bool //
187
morkAtomAidMap::Equal(morkEnv* ev, const void* inKeyA,
188
const void* inKeyB) const
191
return (*(const morkBookAtom**) inKeyA)->EqualAid(
192
*(const morkBookAtom**) inKeyB);
195
/*virtual*/ mork_u4 //
196
morkAtomAidMap::Hash(morkEnv* ev, const void* inKey) const
199
return (*(const morkBookAtom**) inKey)->HashAid();
201
// } ===== end morkMap poly interface =====
202
#endif /*MORK_ENABLE_PROBE_MAPS*/
206
morkAtomAidMap::AddAtom(morkEnv* ev, morkBookAtom* ioAtom)
210
#ifdef MORK_ENABLE_PROBE_MAPS
211
this->MapAtPut(ev, &ioAtom, /*val*/ (void*) 0,
212
/*key*/ (void*) 0, /*val*/ (void*) 0);
213
#else /*MORK_ENABLE_PROBE_MAPS*/
214
this->Put(ev, &ioAtom, /*val*/ (void*) 0,
215
/*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
216
#endif /*MORK_ENABLE_PROBE_MAPS*/
222
morkAtomAidMap::CutAtom(morkEnv* ev, const morkBookAtom* inAtom)
224
morkBookAtom* oldKey = 0;
226
#ifdef MORK_ENABLE_PROBE_MAPS
228
morkProbeMap::ProbeMapCutError(ev);
229
#else /*MORK_ENABLE_PROBE_MAPS*/
230
this->Cut(ev, &inAtom, &oldKey, /*val*/ (void*) 0,
232
#endif /*MORK_ENABLE_PROBE_MAPS*/
238
morkAtomAidMap::GetAtom(morkEnv* ev, const morkBookAtom* inAtom)
240
morkBookAtom* key = 0; // old val in the map
242
#ifdef MORK_ENABLE_PROBE_MAPS
243
this->MapAt(ev, &inAtom, &key, /*val*/ (void*) 0);
244
#else /*MORK_ENABLE_PROBE_MAPS*/
245
this->Get(ev, &inAtom, &key, /*val*/ (void*) 0, (mork_change**) 0);
246
#endif /*MORK_ENABLE_PROBE_MAPS*/
252
morkAtomAidMap::GetAid(morkEnv* ev, mork_aid inAid)
254
morkWeeBookAtom weeAtom(inAid);
255
morkBookAtom* key = &weeAtom; // we need a pointer
256
morkBookAtom* oldKey = 0; // old key in the map
258
#ifdef MORK_ENABLE_PROBE_MAPS
259
this->MapAt(ev, &key, &oldKey, /*val*/ (void*) 0);
260
#else /*MORK_ENABLE_PROBE_MAPS*/
261
this->Get(ev, &key, &oldKey, /*val*/ (void*) 0, (mork_change**) 0);
262
#endif /*MORK_ENABLE_PROBE_MAPS*/
267
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
270
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
272
// ````` ````` ````` ````` `````
273
// { ===== begin morkNode interface =====
275
/*public virtual*/ void
276
morkAtomBodyMap::CloseMorkNode(morkEnv* ev) // CloseAtomBodyMap() only if open
278
if ( this->IsOpenNode() )
281
this->CloseAtomBodyMap(ev);
287
morkAtomBodyMap::~morkAtomBodyMap() // assert CloseAtomBodyMap() executed earlier
289
MORK_ASSERT(this->IsShutNode());
294
morkAtomBodyMap::morkAtomBodyMap(morkEnv* ev, const morkUsage& inUsage,
295
nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
296
#ifdef MORK_ENABLE_PROBE_MAPS
297
: morkProbeMap(ev, inUsage, ioHeap,
298
/*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
299
ioSlotHeap, morkAtomBodyMap_kStartSlotCount,
300
/*inZeroIsClearKey*/ morkBool_kTrue)
301
#else /*MORK_ENABLE_PROBE_MAPS*/
302
: morkMap(ev, inUsage, ioHeap,
303
/*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
304
morkAtomBodyMap_kStartSlotCount, ioSlotHeap,
305
/*inHoldChanges*/ morkBool_kFalse)
306
#endif /*MORK_ENABLE_PROBE_MAPS*/
309
mNode_Derived = morkDerived_kAtomBodyMap;
312
/*public non-poly*/ void
313
morkAtomBodyMap::CloseAtomBodyMap(morkEnv* ev) // called by CloseMorkNode();
317
if ( this->IsNode() )
319
#ifdef MORK_ENABLE_PROBE_MAPS
320
this->CloseProbeMap(ev);
321
#else /*MORK_ENABLE_PROBE_MAPS*/
323
#endif /*MORK_ENABLE_PROBE_MAPS*/
327
this->NonNodeError(ev);
330
ev->NilPointerError();
333
// } ===== end morkNode methods =====
334
// ````` ````` ````` ````` `````
335
#ifdef MORK_ENABLE_PROBE_MAPS
337
/*virtual*/ mork_test // hit(a,b) implies hash(a) == hash(b)
338
morkAtomBodyMap::MapTest(morkEnv* ev, const void* inMapKey,
339
const void* inAppKey) const
341
const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
344
return ( key->EqualFormAndBody(ev, *(const morkBookAtom**) inAppKey) ) ?
345
morkTest_kHit : morkTest_kMiss;
348
return morkTest_kVoid;
351
/*virtual*/ mork_u4 // hit(a,b) implies hash(a) == hash(b)
352
morkAtomBodyMap::MapHash(morkEnv* ev, const void* inAppKey) const
354
const morkBookAtom* key = *(const morkBookAtom**) inAppKey;
356
return key->HashFormAndBody(ev);
362
morkAtomBodyMap::ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const
364
const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
366
return key->HashFormAndBody(ev);
370
#else /*MORK_ENABLE_PROBE_MAPS*/
371
// { ===== begin morkMap poly interface =====
372
/*virtual*/ mork_bool //
373
morkAtomBodyMap::Equal(morkEnv* ev, const void* inKeyA,
374
const void* inKeyB) const
376
return (*(const morkBookAtom**) inKeyA)->EqualFormAndBody(ev,
377
*(const morkBookAtom**) inKeyB);
380
/*virtual*/ mork_u4 //
381
morkAtomBodyMap::Hash(morkEnv* ev, const void* inKey) const
383
return (*(const morkBookAtom**) inKey)->HashFormAndBody(ev);
385
// } ===== end morkMap poly interface =====
386
#endif /*MORK_ENABLE_PROBE_MAPS*/
390
morkAtomBodyMap::AddAtom(morkEnv* ev, morkBookAtom* ioAtom)
394
#ifdef MORK_ENABLE_PROBE_MAPS
395
this->MapAtPut(ev, &ioAtom, /*val*/ (void*) 0,
396
/*key*/ (void*) 0, /*val*/ (void*) 0);
397
#else /*MORK_ENABLE_PROBE_MAPS*/
398
this->Put(ev, &ioAtom, /*val*/ (void*) 0,
399
/*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
400
#endif /*MORK_ENABLE_PROBE_MAPS*/
406
morkAtomBodyMap::CutAtom(morkEnv* ev, const morkBookAtom* inAtom)
408
morkBookAtom* oldKey = 0;
410
#ifdef MORK_ENABLE_PROBE_MAPS
412
morkProbeMap::ProbeMapCutError(ev);
413
#else /*MORK_ENABLE_PROBE_MAPS*/
414
this->Cut(ev, &inAtom, &oldKey, /*val*/ (void*) 0,
416
#endif /*MORK_ENABLE_PROBE_MAPS*/
422
morkAtomBodyMap::GetAtom(morkEnv* ev, const morkBookAtom* inAtom)
424
morkBookAtom* key = 0; // old val in the map
425
#ifdef MORK_ENABLE_PROBE_MAPS
426
this->MapAt(ev, &inAtom, &key, /*val*/ (void*) 0);
427
#else /*MORK_ENABLE_PROBE_MAPS*/
428
this->Get(ev, &inAtom, &key, /*val*/ (void*) 0, (mork_change**) 0);
429
#endif /*MORK_ENABLE_PROBE_MAPS*/
434
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
436
morkAtomRowMap::~morkAtomRowMap()
440
// I changed to sizeof(mork_ip) from sizeof(mork_aid) to fix a crash on
441
// 64 bit machines. I am not sure it was the right way to fix the problem,
442
// but it does stop the crash. Perhaps we should be using the
443
// morkPointerMap instead?
444
morkAtomRowMap::morkAtomRowMap(morkEnv* ev, const morkUsage& inUsage,
445
nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_column inIndexColumn)
446
: morkIntMap(ev, inUsage, sizeof(mork_ip), ioHeap, ioSlotHeap,
447
/*inHoldChanges*/ morkBool_kFalse)
448
, mAtomRowMap_IndexColumn( inIndexColumn )
451
mNode_Derived = morkDerived_kAtomRowMap;
454
void morkAtomRowMap::AddRow(morkEnv* ev, morkRow* ioRow)
455
// add ioRow only if it contains a cell in mAtomRowMap_IndexColumn.
457
mork_aid aid = ioRow->GetCellAtomAid(ev, mAtomRowMap_IndexColumn);
459
this->AddAid(ev, aid, ioRow);
462
void morkAtomRowMap::CutRow(morkEnv* ev, morkRow* ioRow)
463
// cut ioRow only if it contains a cell in mAtomRowMap_IndexColumn.
465
mork_aid aid = ioRow->GetCellAtomAid(ev, mAtomRowMap_IndexColumn);
467
this->CutAid(ev, aid);
470
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789