| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEBUCKET_H |
| 22 |
#define KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEBUCKET_H |
| 23 |
|
| 24 |
// Namespace includes |
| 25 |
#include "ContainerSettings.h" |
| 26 |
|
| 27 |
// Library includes |
| 28 |
|
| 29 |
// Other includes |
| 30 |
#include "Context/CContext.h" |
| 31 |
|
| 32 |
// Logger includes |
| 33 |
|
| 34 |
|
| 35 |
namespace Konclude { |
| 36 |
|
| 37 |
using namespace Context; |
| 38 |
|
| 39 |
namespace Utilities { |
| 40 |
|
| 41 |
namespace Container { |
| 42 |
|
| 43 |
|
| 44 |
/*! |
| 45 |
* |
| 46 |
* \class CDynamicReferenceBucketBase |
| 47 |
* \author Andreas Steigmiller |
| 48 |
* \version 0.1 |
| 49 |
* \brief TODO |
| 50 |
* |
| 51 |
*/ |
| 52 |
template<class T, cint64 bucket2Size = 5> |
| 53 |
class CDynamicReferenceBucketBase { |
| 54 |
// public methods |
| 55 |
public: |
| 56 |
//! Constructor |
| 57 |
inline CDynamicReferenceBucketBase(CContext* context = nullptr); |
| 58 |
|
| 59 |
//! Destructor |
| 60 |
inline ~CDynamicReferenceBucketBase(); |
| 61 |
|
| 62 |
inline void initBucket(cint64 bucketDepth, CDynamicReferenceBucketBase<T,bucket2Size>* referenceBucket = nullptr); |
| 63 |
|
| 64 |
inline const T getData(cint64 index, const T& defaultValue); |
| 65 |
inline const T getData(cint64 index, const T& defaultValue, bool* localFlag); |
| 66 |
inline const T getLocalData(cint64 index, const T& defaultValue); |
| 67 |
inline const T getReferenceData(cint64 index, const T& defaultValue); |
| 68 |
|
| 69 |
inline void setLocalData(cint64 index, const T& data); |
| 70 |
inline void setData(cint64 index, const T& data); |
| 71 |
|
| 72 |
inline bool hasLocalData(cint64 index); |
| 73 |
inline bool hasReferencedData(cint64 index); |
| 74 |
inline bool hasData(cint64 index); |
| 75 |
|
| 76 |
inline void installBucket(cint64 index, CDynamicReferenceBucketBase<T,bucket2Size>* bucket); |
| 77 |
|
| 78 |
// protected variables |
| 79 |
protected: |
| 80 |
union CBucketDataPair { |
| 81 |
T mData; |
| 82 |
CDynamicReferenceBucketBase<T,bucket2Size>* mBucket; |
| 83 |
}; |
| 84 |
|
| 85 |
struct CReferenceBucketDataPair { |
| 86 |
bool mReferenced; |
| 87 |
bool mUninitialized; |
| 88 |
CBucketDataPair mBucketData; |
| 89 |
}; |
| 90 |
|
| 91 |
// protected methods |
| 92 |
protected: |
| 93 |
inline cint64 getBucketIndex(cint64 index); |
| 94 |
inline cint64 getBucketIndex(cint64 index, CDynamicReferenceBucketBase<T,bucket2Size>* bucket); |
| 95 |
|
| 96 |
inline CDynamicReferenceBucketBase<T,bucket2Size>* getRelevantReferenceBucket(CDynamicReferenceBucketBase<T,bucket2Size>* bucket); |
| 97 |
inline CDynamicReferenceBucketBase<T,bucket2Size>* getUpdatedRelevantReferenceBucket(CDynamicReferenceBucketBase<T,bucket2Size>* bucket); |
| 98 |
|
| 99 |
|
| 100 |
inline CReferenceBucketDataPair* createBucketVector(CDynamicReferenceBucketBase<T,bucket2Size>* bucket, bool baseVector) { |
| 101 |
CReferenceBucketDataPair* refVector = nullptr; |
| 102 |
if (bucket) { |
| 103 |
refVector = bucket->mVec; |
| 104 |
} |
| 105 |
CReferenceBucketDataPair* vector = CObjectAllocator<CReferenceBucketDataPair>::allocateArray(mMemMan,BUCKETSIZE); |
| 106 |
for (cint64 ind = 0; ind < BUCKETSIZE; ++ind) { |
| 107 |
CReferenceBucketDataPair* refBucketDataPair = &vector[ind]; |
| 108 |
if (refVector) { |
| 109 |
if (baseVector) { |
| 110 |
refBucketDataPair->mReferenced = true; |
| 111 |
refBucketDataPair->mUninitialized = refVector[ind].mUninitialized; |
| 112 |
refBucketDataPair->mBucketData.mData = refVector[ind].mBucketData.mData; |
| 113 |
} else { |
| 114 |
refBucketDataPair->mReferenced = true; |
| 115 |
refBucketDataPair->mUninitialized = false; |
| 116 |
refBucketDataPair->mBucketData.mBucket = refVector[ind].mBucketData.mBucket; |
| 117 |
} |
| 118 |
} else { |
| 119 |
refBucketDataPair->mReferenced = false; |
| 120 |
refBucketDataPair->mUninitialized = true; |
| 121 |
refBucketDataPair->mBucketData.mBucket = nullptr; |
| 122 |
} |
| 123 |
} |
| 124 |
return vector; |
| 125 |
} |
| 126 |
|
| 127 |
inline CDynamicReferenceBucketBase<T,bucket2Size>* createBucket(cint64 bucketDepth, CReferenceBucketDataPair* bucketPos); |
| 128 |
|
| 129 |
// protected variables |
| 130 |
protected: |
| 131 |
CDynamicReferenceBucketBase<T,bucket2Size>* mReferenceBucket; |
| 132 |
CReferenceBucketDataPair* mVec; |
| 133 |
cint64 mBucketDepth; |
| 134 |
|
| 135 |
CContext* mContext; |
| 136 |
CMemoryAllocationManager* mMemMan; |
| 137 |
|
| 138 |
static const cint64 BUCKETSIZE = 2<<bucket2Size; |
| 139 |
static const cint64 BUCKETINDEXMASK = BUCKETSIZE-1; |
| 140 |
|
| 141 |
// private methods |
| 142 |
private: |
| 143 |
|
| 144 |
// private variables |
| 145 |
private: |
| 146 |
}; |
| 147 |
|
| 148 |
class CTestDynamicReferenceBucketBase : public CDynamicReferenceBucketBase<cint64> { |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
}; // end namespace Container |
| 154 |
|
| 155 |
}; // end namespace Utilities |
| 156 |
|
| 157 |
}; // end namespace Konclude |
| 158 |
|
| 159 |
#include "CDynamicReferenceBucket.cpp" |
| 160 |
|
| 161 |
#endif // KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEBUCKET_H |