Back to index

lightning-sunbird  0.9+nobinonly
morkAtomMap.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MORKATOMMAP_
00039 #define _MORKATOMMAP_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKMAP_
00050 #include "morkMap.h"
00051 #endif
00052 
00053 #ifndef _MORKPROBEMAP_
00054 #include "morkProbeMap.h"
00055 #endif
00056 
00057 #ifndef _MORKINTMAP_
00058 #include "morkIntMap.h"
00059 #endif
00060 
00061 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00062 
00063 #define morkDerived_kAtomAidMap  /*i*/ 0x6141 /* ascii 'aA' */
00064 
00065 #define morkAtomAidMap_kStartSlotCount 23
00066 
00067 /*| morkAtomAidMap: keys of morkBookAtom organized by atom ID
00068 |*/
00069 #ifdef MORK_ENABLE_PROBE_MAPS
00070 class morkAtomAidMap : public morkProbeMap { // for mapping tokens to maps
00071 #else /*MORK_ENABLE_PROBE_MAPS*/
00072 class morkAtomAidMap : public morkMap { // for mapping tokens to maps
00073 #endif /*MORK_ENABLE_PROBE_MAPS*/
00074 
00075 // { ===== begin morkNode interface =====
00076 public: // morkNode virtual methods
00077   virtual void CloseMorkNode(morkEnv* ev); // CloseAtomAidMap() only if open
00078   virtual ~morkAtomAidMap(); // assert that CloseAtomAidMap() executed earlier
00079   
00080 public: // morkMap construction & destruction
00081   morkAtomAidMap(morkEnv* ev, const morkUsage& inUsage,
00082     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00083   void CloseAtomAidMap(morkEnv* ev); // called by CloseMorkNode();
00084 
00085 public: // dynamic type identification
00086   mork_bool IsAtomAidMap() const
00087   { return IsNode() && mNode_Derived == morkDerived_kAtomAidMap; }
00088 // } ===== end morkNode methods =====
00089 
00090 public:
00091 #ifdef MORK_ENABLE_PROBE_MAPS
00092   // { ===== begin morkProbeMap methods =====
00093   virtual mork_test // hit(a,b) implies hash(a) == hash(b)
00094   MapTest(morkEnv* ev, const void* inMapKey, const void* inAppKey) const;
00095 
00096   virtual mork_u4 // hit(a,b) implies hash(a) == hash(b)
00097   MapHash(morkEnv* ev, const void* inAppKey) const;
00098 
00099   virtual mork_u4 ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const;
00100 
00101   // virtual mork_bool ProbeMapIsKeyNil(morkEnv* ev, void* ioMapKey);
00102 
00103   // virtual void ProbeMapClearKey(morkEnv* ev, // put 'nil' alls keys inside map
00104   //   void* ioMapKey, mork_count inKeyCount); // array of keys inside map
00105 
00106   // virtual void ProbeMapPushIn(morkEnv* ev, // move (key,val) into the map
00107   //   const void* inAppKey, const void* inAppVal, // (key,val) outside map
00108   //   void* outMapKey, void* outMapVal);      // (key,val) inside map
00109 
00110   // virtual void ProbeMapPullOut(morkEnv* ev, // move (key,val) out from the map
00111   //   const void* inMapKey, const void* inMapVal, // (key,val) inside map
00112   //   void* outAppKey, void* outAppVal) const;    // (key,val) outside map
00113   // } ===== end morkProbeMap methods =====
00114 #else /*MORK_ENABLE_PROBE_MAPS*/
00115 // { ===== begin morkMap poly interface =====
00116   virtual mork_bool // note: equal(a,b) implies hash(a) == hash(b)
00117   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00118   // implemented using morkBookAtom::HashAid()
00119 
00120   virtual mork_u4 // note: equal(a,b) implies hash(a) == hash(b)
00121   Hash(morkEnv* ev, const void* inKey) const;
00122   // implemented using morkBookAtom::EqualAid()
00123 // } ===== end morkMap poly interface =====
00124 #endif /*MORK_ENABLE_PROBE_MAPS*/
00125 
00126 public: // other map methods
00127 
00128   mork_bool      AddAtom(morkEnv* ev, morkBookAtom* ioAtom);
00129   // AddAtom() returns ev->Good()
00130 
00131   morkBookAtom*  CutAtom(morkEnv* ev, const morkBookAtom* inAtom);
00132   // CutAtom() returns the atom removed equal to inAtom, if there was one
00133   
00134   morkBookAtom*  GetAtom(morkEnv* ev, const morkBookAtom* inAtom);
00135   // GetAtom() returns the atom equal to inAtom, or else nil
00136 
00137   morkBookAtom*  GetAid(morkEnv* ev, mork_aid inAid);
00138   // GetAid() returns the atom equal to inAid, or else nil
00139 
00140   // note the atoms are owned elsewhere, usuall by morkAtomSpace
00141 
00142 public: // typesafe refcounting inlines calling inherited morkNode methods
00143   static void SlotWeakAtomAidMap(morkAtomAidMap* me,
00144     morkEnv* ev, morkAtomAidMap** ioSlot)
00145   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00146   
00147   static void SlotStrongAtomAidMap(morkAtomAidMap* me,
00148     morkEnv* ev, morkAtomAidMap** ioSlot)
00149   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00150 };
00151 
00152 #ifdef MORK_ENABLE_PROBE_MAPS
00153 class morkAtomAidMapIter: public morkProbeMapIter { // typesafe wrapper class
00154 #else /*MORK_ENABLE_PROBE_MAPS*/
00155 class morkAtomAidMapIter: public morkMapIter { // typesafe wrapper class
00156 #endif /*MORK_ENABLE_PROBE_MAPS*/
00157 
00158 public:
00159 #ifdef MORK_ENABLE_PROBE_MAPS
00160   morkAtomAidMapIter(morkEnv* ev, morkAtomAidMap* ioMap)
00161   : morkProbeMapIter(ev, ioMap) { }
00162  
00163   morkAtomAidMapIter( ) : morkProbeMapIter()  { }
00164 #else /*MORK_ENABLE_PROBE_MAPS*/
00165   morkAtomAidMapIter(morkEnv* ev, morkAtomAidMap* ioMap)
00166   : morkMapIter(ev, ioMap) { }
00167  
00168   morkAtomAidMapIter( ) : morkMapIter()  { }
00169 #endif /*MORK_ENABLE_PROBE_MAPS*/
00170 
00171   void InitAtomAidMapIter(morkEnv* ev, morkAtomAidMap* ioMap)
00172   { this->InitMapIter(ev, ioMap); }
00173    
00174   mork_change* FirstAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00175   { return this->First(ev, outAtomPtr, /*val*/ (void*) 0); }
00176   
00177   mork_change* NextAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00178   { return this->Next(ev, outAtomPtr, /*val*/ (void*) 0); }
00179   
00180   mork_change* HereAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00181   { return this->Here(ev, outAtomPtr, /*val*/ (void*) 0); }
00182   
00183   mork_change* CutHereAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00184   { return this->CutHere(ev, outAtomPtr, /*val*/ (void*) 0); }
00185 };
00186 
00187 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00188 
00189 
00190 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00191 
00192 #define morkDerived_kAtomBodyMap  /*i*/ 0x6142 /* ascii 'aB' */
00193 
00194 #define morkAtomBodyMap_kStartSlotCount 23
00195 
00196 /*| morkAtomBodyMap: keys of morkBookAtom organized by body bytes
00197 |*/
00198 #ifdef MORK_ENABLE_PROBE_MAPS
00199 class morkAtomBodyMap : public morkProbeMap { // for mapping tokens to maps
00200 #else /*MORK_ENABLE_PROBE_MAPS*/
00201 class morkAtomBodyMap : public morkMap { // for mapping tokens to maps
00202 #endif /*MORK_ENABLE_PROBE_MAPS*/
00203 
00204 // { ===== begin morkNode interface =====
00205 public: // morkNode virtual methods
00206   virtual void CloseMorkNode(morkEnv* ev); // CloseAtomBodyMap() only if open
00207   virtual ~morkAtomBodyMap(); // assert CloseAtomBodyMap() executed earlier
00208   
00209 public: // morkMap construction & destruction
00210   morkAtomBodyMap(morkEnv* ev, const morkUsage& inUsage,
00211     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00212   void CloseAtomBodyMap(morkEnv* ev); // called by CloseMorkNode();
00213 
00214 public: // dynamic type identification
00215   mork_bool IsAtomBodyMap() const
00216   { return IsNode() && mNode_Derived == morkDerived_kAtomBodyMap; }
00217 // } ===== end morkNode methods =====
00218 
00219 public:
00220 #ifdef MORK_ENABLE_PROBE_MAPS
00221   // { ===== begin morkProbeMap methods =====
00222   virtual mork_test // hit(a,b) implies hash(a) == hash(b)
00223   MapTest(morkEnv* ev, const void* inMapKey, const void* inAppKey) const;
00224 
00225   virtual mork_u4 // hit(a,b) implies hash(a) == hash(b)
00226   MapHash(morkEnv* ev, const void* inAppKey) const;
00227 
00228   virtual mork_u4 ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const;
00229 
00230   // virtual mork_bool ProbeMapIsKeyNil(morkEnv* ev, void* ioMapKey);
00231 
00232   // virtual void ProbeMapClearKey(morkEnv* ev, // put 'nil' alls keys inside map
00233   //   void* ioMapKey, mork_count inKeyCount); // array of keys inside map
00234 
00235   // virtual void ProbeMapPushIn(morkEnv* ev, // move (key,val) into the map
00236   //   const void* inAppKey, const void* inAppVal, // (key,val) outside map
00237   //   void* outMapKey, void* outMapVal);      // (key,val) inside map
00238 
00239   // virtual void ProbeMapPullOut(morkEnv* ev, // move (key,val) out from the map
00240   //   const void* inMapKey, const void* inMapVal, // (key,val) inside map
00241   //   void* outAppKey, void* outAppVal) const;    // (key,val) outside map
00242   // } ===== end morkProbeMap methods =====
00243 #else /*MORK_ENABLE_PROBE_MAPS*/
00244 // { ===== begin morkMap poly interface =====
00245   virtual mork_bool // note: equal(a,b) implies hash(a) == hash(b)
00246   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00247   // implemented using morkBookAtom::EqualFormAndBody()
00248 
00249   virtual mork_u4 // note: equal(a,b) implies hash(a) == hash(b)
00250   Hash(morkEnv* ev, const void* inKey) const;
00251   // implemented using morkBookAtom::HashFormAndBody()
00252 // } ===== end morkMap poly interface =====
00253 #endif /*MORK_ENABLE_PROBE_MAPS*/
00254 
00255 public: // other map methods
00256 
00257   mork_bool      AddAtom(morkEnv* ev, morkBookAtom* ioAtom);
00258   // AddAtom() returns ev->Good()
00259 
00260   morkBookAtom*  CutAtom(morkEnv* ev, const morkBookAtom* inAtom);
00261   // CutAtom() returns the atom removed equal to inAtom, if there was one
00262   
00263   morkBookAtom*  GetAtom(morkEnv* ev, const morkBookAtom* inAtom);
00264   // GetAtom() returns the atom equal to inAtom, or else nil
00265 
00266   // note the atoms are owned elsewhere, usuall by morkAtomSpace
00267 
00268 public: // typesafe refcounting inlines calling inherited morkNode methods
00269   static void SlotWeakAtomBodyMap(morkAtomBodyMap* me,
00270     morkEnv* ev, morkAtomBodyMap** ioSlot)
00271   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00272   
00273   static void SlotStrongAtomBodyMap(morkAtomBodyMap* me,
00274     morkEnv* ev, morkAtomBodyMap** ioSlot)
00275   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00276 };
00277 
00278 #ifdef MORK_ENABLE_PROBE_MAPS
00279 class morkAtomBodyMapIter: public morkProbeMapIter{ // typesafe wrapper class
00280 #else /*MORK_ENABLE_PROBE_MAPS*/
00281 class morkAtomBodyMapIter: public morkMapIter{ // typesafe wrapper class
00282 #endif /*MORK_ENABLE_PROBE_MAPS*/
00283 
00284 public:
00285 #ifdef MORK_ENABLE_PROBE_MAPS
00286   morkAtomBodyMapIter(morkEnv* ev, morkAtomBodyMap* ioMap)
00287   : morkProbeMapIter(ev, ioMap) { }
00288  
00289   morkAtomBodyMapIter( ) : morkProbeMapIter()  { }
00290 #else /*MORK_ENABLE_PROBE_MAPS*/
00291   morkAtomBodyMapIter(morkEnv* ev, morkAtomBodyMap* ioMap)
00292   : morkMapIter(ev, ioMap) { }
00293  
00294   morkAtomBodyMapIter( ) : morkMapIter()  { }
00295 #endif /*MORK_ENABLE_PROBE_MAPS*/
00296   
00297   void InitAtomBodyMapIter(morkEnv* ev, morkAtomBodyMap* ioMap)
00298   { this->InitMapIter(ev, ioMap); }
00299    
00300   mork_change* FirstAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00301   { return this->First(ev, outAtomPtr, /*val*/ (void*) 0); }
00302   
00303   mork_change* NextAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00304   { return this->Next(ev, outAtomPtr, /*val*/ (void*) 0); }
00305   
00306   mork_change* HereAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00307   { return this->Here(ev, outAtomPtr, /*val*/ (void*) 0); }
00308   
00309   mork_change* CutHereAtom(morkEnv* ev, morkBookAtom** outAtomPtr)
00310   { return this->CutHere(ev, outAtomPtr, /*val*/ (void*) 0); }
00311 };
00312 
00313 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00314 
00315 #define morkDerived_kAtomRowMap  /*i*/ 0x6152 /* ascii 'aR' */
00316 
00317 /*| morkAtomRowMap: maps morkAtom* -> morkRow*
00318 |*/
00319 class morkAtomRowMap : public morkIntMap { // for mapping atoms to rows
00320 
00321 public:
00322   mork_column mAtomRowMap_IndexColumn; // row column being indexed
00323 
00324 public:
00325 
00326   virtual ~morkAtomRowMap();
00327   morkAtomRowMap(morkEnv* ev, const morkUsage& inUsage,
00328     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_column inIndexColumn);
00329 
00330 public: // adding and cutting from morkRow instance candidate
00331 
00332   void  AddRow(morkEnv* ev, morkRow* ioRow);
00333   // add ioRow only if it contains a cell in mAtomRowMap_IndexColumn. 
00334 
00335   void  CutRow(morkEnv* ev, morkRow* ioRow);
00336   // cut ioRow only if it contains a cell in mAtomRowMap_IndexColumn. 
00337 
00338 public: // other map methods
00339 
00340   mork_bool  AddAid(morkEnv* ev, mork_aid inAid, morkRow* ioRow)
00341   { return this->AddInt(ev, inAid, ioRow); }
00342   // the AddAid() boolean return equals ev->Good().
00343 
00344   mork_bool  CutAid(morkEnv* ev, mork_aid inAid)
00345   { return this->CutInt(ev, inAid); }
00346   // The CutAid() boolean return indicates whether removal happened. 
00347   
00348   morkRow*   GetAid(morkEnv* ev, mork_aid inAid)
00349   { return (morkRow*) this->GetInt(ev, inAid); }
00350   // Note the returned space does NOT have an increase in refcount for this.
00351   
00352 public: // dynamic type identification
00353   mork_bool IsAtomRowMap() const
00354   { return IsNode() && mNode_Derived == morkDerived_kAtomRowMap; }
00355 
00356 public: // typesafe refcounting inlines calling inherited morkNode methods
00357   static void SlotWeakAtomRowMap(morkAtomRowMap* me,
00358     morkEnv* ev, morkAtomRowMap** ioSlot)
00359   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00360   
00361   static void SlotStrongAtomRowMap(morkAtomRowMap* me,
00362     morkEnv* ev, morkAtomRowMap** ioSlot)
00363   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00364 
00365 };
00366 
00367 class morkAtomRowMapIter: public morkMapIter{ // typesafe wrapper class
00368 
00369 public:
00370   morkAtomRowMapIter(morkEnv* ev, morkAtomRowMap* ioMap)
00371   : morkMapIter(ev, ioMap) { }
00372  
00373   morkAtomRowMapIter( ) : morkMapIter()  { }
00374   void InitAtomRowMapIter(morkEnv* ev, morkAtomRowMap* ioMap)
00375   { this->InitMapIter(ev, ioMap); }
00376    
00377   mork_change*
00378   FirstAtomAndRow(morkEnv* ev, morkAtom** outAtom, morkRow** outRow)
00379   { return this->First(ev, outAtom, outRow); }
00380   
00381   mork_change*
00382   NextAtomAndRow(morkEnv* ev, morkAtom** outAtom, morkRow** outRow)
00383   { return this->Next(ev, outAtom, outRow); }
00384   
00385   mork_change*
00386   HereAtomAndRow(morkEnv* ev, morkAtom** outAtom, morkRow** outRow)
00387   { return this->Here(ev, outAtom, outRow); }
00388   
00389   mork_change*
00390   CutHereAtomAndRow(morkEnv* ev, morkAtom** outAtom, morkRow** outRow)
00391   { return this->CutHere(ev, outAtom, outRow); }
00392 };
00393 
00394 
00395 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00396 
00397 #endif /* _MORKATOMMAP_ */