parent
0a190a389f
commit
4fbf4f8340
|
@ -25,6 +25,13 @@
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
/* static */ Ver4DictBuffers::Ver4DictBuffersPtr Ver4DictBuffers::openVer4DictBuffers(
|
||||||
|
const char *const dictDirPath, const MmappedBuffer::MmappedBufferPtr &headerBuffer) {
|
||||||
|
const bool isUpdatable = headerBuffer.get() ? headerBuffer.get()->isUpdatable() : false;
|
||||||
|
// TODO: take only dictDirPath, and open both header and trie files in the constructor below
|
||||||
|
return Ver4DictBuffersPtr(new Ver4DictBuffers(dictDirPath, headerBuffer, isUpdatable));
|
||||||
|
}
|
||||||
|
|
||||||
bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
|
bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
|
||||||
const BufferWithExtendableBuffer *const headerBuffer) const {
|
const BufferWithExtendableBuffer *const headerBuffer) const {
|
||||||
// Create temporary directory.
|
// Create temporary directory.
|
||||||
|
@ -91,4 +98,32 @@ bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ver4DictBuffers::Ver4DictBuffers(const char *const dictDirPath,
|
||||||
|
const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable)
|
||||||
|
: mHeaderBuffer(headerBuffer),
|
||||||
|
mDictBuffer(MmappedBuffer::openBuffer(dictDirPath,
|
||||||
|
Ver4DictConstants::TRIE_FILE_EXTENSION, isUpdatable)),
|
||||||
|
mHeaderPolicy(headerBuffer.get()->getBuffer(), FormatUtils::VERSION_4),
|
||||||
|
mExpandableHeaderBuffer(headerBuffer.get()->getBuffer(), mHeaderPolicy.getSize(),
|
||||||
|
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
|
||||||
|
mExpandableTrieBuffer(mDictBuffer.get()->getBuffer(),
|
||||||
|
mDictBuffer.get()->getBufferSize(),
|
||||||
|
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
|
||||||
|
mTerminalPositionLookupTable(dictDirPath, isUpdatable),
|
||||||
|
mProbabilityDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
|
||||||
|
isUpdatable),
|
||||||
|
mBigramDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
|
||||||
|
isUpdatable),
|
||||||
|
mShortcutDictContent(dictDirPath, isUpdatable),
|
||||||
|
mIsUpdatable(isUpdatable) {}
|
||||||
|
|
||||||
|
Ver4DictBuffers::Ver4DictBuffers(const HeaderPolicy *const headerPolicy)
|
||||||
|
: mHeaderBuffer(0), mDictBuffer(0), mHeaderPolicy(),
|
||||||
|
mExpandableHeaderBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
|
||||||
|
mExpandableTrieBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
|
||||||
|
mTerminalPositionLookupTable(),
|
||||||
|
mProbabilityDictContent(headerPolicy->hasHistoricalInfoOfWords()),
|
||||||
|
mBigramDictContent(headerPolicy->hasHistoricalInfoOfWords()), mShortcutDictContent(),
|
||||||
|
mIsUpdatable(true) {}
|
||||||
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -33,12 +33,8 @@ class Ver4DictBuffers {
|
||||||
public:
|
public:
|
||||||
typedef ExclusiveOwnershipPointer<Ver4DictBuffers> Ver4DictBuffersPtr;
|
typedef ExclusiveOwnershipPointer<Ver4DictBuffers> Ver4DictBuffersPtr;
|
||||||
|
|
||||||
static AK_FORCE_INLINE Ver4DictBuffersPtr openVer4DictBuffers(const char *const dictDirPath,
|
static Ver4DictBuffersPtr openVer4DictBuffers(const char *const dictDirPath,
|
||||||
const MmappedBuffer::MmappedBufferPtr &headerBuffer) {
|
const MmappedBuffer::MmappedBufferPtr &headerBuffer);
|
||||||
const bool isUpdatable = headerBuffer.get() ? headerBuffer.get()->isUpdatable() : false;
|
|
||||||
// TODO: take only dictDirPath, and open both header and trie files in the constructor below
|
|
||||||
return Ver4DictBuffersPtr(new Ver4DictBuffers(dictDirPath, headerBuffer, isUpdatable));
|
|
||||||
}
|
|
||||||
|
|
||||||
static AK_FORCE_INLINE Ver4DictBuffersPtr createVer4DictBuffers(
|
static AK_FORCE_INLINE Ver4DictBuffersPtr createVer4DictBuffers(
|
||||||
const HeaderPolicy *const headerPolicy) {
|
const HeaderPolicy *const headerPolicy) {
|
||||||
|
@ -121,33 +117,10 @@ class Ver4DictBuffers {
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(Ver4DictBuffers);
|
DISALLOW_COPY_AND_ASSIGN(Ver4DictBuffers);
|
||||||
|
|
||||||
AK_FORCE_INLINE Ver4DictBuffers(const char *const dictDirPath,
|
Ver4DictBuffers(const char *const dictDirPath,
|
||||||
const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable)
|
const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable);
|
||||||
: mHeaderBuffer(headerBuffer),
|
|
||||||
mDictBuffer(MmappedBuffer::openBuffer(dictDirPath,
|
|
||||||
Ver4DictConstants::TRIE_FILE_EXTENSION, isUpdatable)),
|
|
||||||
mHeaderPolicy(headerBuffer.get()->getBuffer(), FormatUtils::VERSION_4),
|
|
||||||
mExpandableHeaderBuffer(headerBuffer.get()->getBuffer(), mHeaderPolicy.getSize(),
|
|
||||||
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
|
|
||||||
mExpandableTrieBuffer(mDictBuffer.get()->getBuffer(),
|
|
||||||
mDictBuffer.get()->getBufferSize(),
|
|
||||||
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
|
|
||||||
mTerminalPositionLookupTable(dictDirPath, isUpdatable),
|
|
||||||
mProbabilityDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
|
|
||||||
isUpdatable),
|
|
||||||
mBigramDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
|
|
||||||
isUpdatable),
|
|
||||||
mShortcutDictContent(dictDirPath, isUpdatable),
|
|
||||||
mIsUpdatable(isUpdatable) {}
|
|
||||||
|
|
||||||
AK_FORCE_INLINE Ver4DictBuffers(const HeaderPolicy *const headerPolicy)
|
Ver4DictBuffers(const HeaderPolicy *const headerPolicy);
|
||||||
: mHeaderBuffer(0), mDictBuffer(0), mHeaderPolicy(),
|
|
||||||
mExpandableHeaderBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
|
|
||||||
mExpandableTrieBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
|
|
||||||
mTerminalPositionLookupTable(),
|
|
||||||
mProbabilityDictContent(headerPolicy->hasHistoricalInfoOfWords()),
|
|
||||||
mBigramDictContent(headerPolicy->hasHistoricalInfoOfWords()), mShortcutDictContent(),
|
|
||||||
mIsUpdatable(true) {}
|
|
||||||
|
|
||||||
const MmappedBuffer::MmappedBufferPtr mHeaderBuffer;
|
const MmappedBuffer::MmappedBufferPtr mHeaderBuffer;
|
||||||
const MmappedBuffer::MmappedBufferPtr mDictBuffer;
|
const MmappedBuffer::MmappedBufferPtr mDictBuffer;
|
||||||
|
|
|
@ -25,22 +25,23 @@ template<class T>
|
||||||
class ExclusiveOwnershipPointer {
|
class ExclusiveOwnershipPointer {
|
||||||
public:
|
public:
|
||||||
// This instance become an owner of the raw pointer.
|
// This instance become an owner of the raw pointer.
|
||||||
ExclusiveOwnershipPointer(T *const rawPointer)
|
AK_FORCE_INLINE ExclusiveOwnershipPointer(T *const rawPointer)
|
||||||
: mPointer(rawPointer),
|
: mPointer(rawPointer),
|
||||||
mSharedOwnerPtr(new (ExclusiveOwnershipPointer<T> *)(this)) {}
|
mSharedOwnerPtr(new (ExclusiveOwnershipPointer<T> *)(this)) {}
|
||||||
|
|
||||||
// Move the ownership.
|
// Move the ownership.
|
||||||
ExclusiveOwnershipPointer(const ExclusiveOwnershipPointer<T> &pointer)
|
AK_FORCE_INLINE ExclusiveOwnershipPointer(const ExclusiveOwnershipPointer<T> &pointer)
|
||||||
: mPointer(pointer.mPointer), mSharedOwnerPtr(pointer.mSharedOwnerPtr) {
|
: mPointer(pointer.mPointer), mSharedOwnerPtr(pointer.mSharedOwnerPtr) {
|
||||||
transferOwnership(&pointer);
|
transferOwnership(&pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ExclusiveOwnershipPointer() {
|
AK_FORCE_INLINE ~ExclusiveOwnershipPointer() {
|
||||||
deletePointersIfHavingOwnership();
|
deletePointersIfHavingOwnership();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the ownership.
|
// Move the ownership.
|
||||||
ExclusiveOwnershipPointer<T> &operator=(const ExclusiveOwnershipPointer<T> &pointer) {
|
AK_FORCE_INLINE ExclusiveOwnershipPointer<T> &operator=(
|
||||||
|
const ExclusiveOwnershipPointer<T> &pointer) {
|
||||||
// Delete pointers when this is an owner of another pointer.
|
// Delete pointers when this is an owner of another pointer.
|
||||||
deletePointersIfHavingOwnership();
|
deletePointersIfHavingOwnership();
|
||||||
mPointer = pointer.mPointer;
|
mPointer = pointer.mPointer;
|
||||||
|
@ -49,7 +50,7 @@ class ExclusiveOwnershipPointer {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *get() const {
|
AK_FORCE_INLINE T *get() const {
|
||||||
return mPointer;
|
return mPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue