1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/graphite2/src/inc/SegCacheEntry.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* GRAPHITE2 LICENSING 1.5 + 1.6 + Copyright 2010, SIL International 1.7 + All rights reserved. 1.8 + 1.9 + This library is free software; you can redistribute it and/or modify 1.10 + it under the terms of the GNU Lesser General Public License as published 1.11 + by the Free Software Foundation; either version 2.1 of License, or 1.12 + (at your option) any later version. 1.13 + 1.14 + This program is distributed in the hope that it will be useful, 1.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + Lesser General Public License for more details. 1.18 + 1.19 + You should also have received a copy of the GNU Lesser General Public 1.20 + License along with this library in the file named "LICENSE". 1.21 + If not, write to the Free Software Foundation, 51 Franklin Street, 1.22 + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 1.23 + internet at http://www.fsf.org/licenses/lgpl.html. 1.24 + 1.25 +Alternatively, the contents of this file may be used under the terms of the 1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public 1.27 +License, as published by the Free Software Foundation, either version 2 1.28 +of the License or (at your option) any later version. 1.29 +*/ 1.30 +#pragma once 1.31 + 1.32 +#ifndef GRAPHITE2_NSEGCACHE 1.33 + 1.34 +#include "inc/Main.h" 1.35 +#include "inc/Slot.h" 1.36 + 1.37 +namespace graphite2 { 1.38 + 1.39 +class Segment; 1.40 +class Slot; 1.41 +class SegCacheEntry; 1.42 +class SegCachePrefixEntry; 1.43 + 1.44 +enum SegCacheParameters { 1.45 + /** number of characters used in initial prefix tree */ 1.46 + ePrefixLength = 2, 1.47 + /** Segments more recent than maxSegmentCount() / eAgeFactor are kept */ 1.48 + eAgeFactor = 4, 1.49 + /** Segments are purged according to the formular: 1.50 + * accessCount < (totalAccesses)/(ePurgeFactor * maxSegments) */ 1.51 + ePurgeFactor = 5, 1.52 + /** Maximum number of Segments to store which have the same 1.53 + * prefix. Needed to prevent unique identifiers flooding the cache */ 1.54 + eMaxSuffixCount = 15 1.55 + 1.56 +}; 1.57 + 1.58 +class SegCacheCharInfo 1.59 +{ 1.60 +public: 1.61 + uint16 m_unicode; 1.62 + uint16 m_before; 1.63 + uint16 m_after; 1.64 +}; 1.65 + 1.66 +/** 1.67 + * SegCacheEntry stores the result of running the engine for specific unicode 1.68 + * code points in the typical mid-line situation. 1.69 + */ 1.70 +class SegCacheEntry 1.71 +{ 1.72 + // Prevent any implict copying; 1.73 + SegCacheEntry(const SegCacheEntry &); 1.74 + SegCacheEntry & operator = (const SegCacheEntry &); 1.75 + 1.76 + friend class SegCachePrefixEntry; 1.77 +public: 1.78 + SegCacheEntry() : 1.79 + m_glyphLength(0), m_unicode(NULL), m_glyph(NULL), m_attr(NULL), m_justs(0), 1.80 + m_accessCount(0), m_lastAccess(0) 1.81 + {} 1.82 + SegCacheEntry(const uint16 * cmapGlyphs, size_t length, Segment * seg, size_t charOffset, long long cacheTime); 1.83 + ~SegCacheEntry() { clear(); }; 1.84 + void clear(); 1.85 + size_t glyphLength() const { return m_glyphLength; } 1.86 + const Slot * first() const { return m_glyph; } 1.87 + const Slot * last() const { return m_glyph + (m_glyphLength - 1); } 1.88 + 1.89 + /** Total number of times this entry has been accessed since creation */ 1.90 + unsigned long long accessCount() const { return m_accessCount; } 1.91 + /** "time" of last access where "time" is measured in accesses to the cache owning this entry */ 1.92 + void accessed(unsigned long long cacheTime) const 1.93 + { 1.94 + m_lastAccess = cacheTime; ++m_accessCount; 1.95 + }; 1.96 + 1.97 + int compareRank(const SegCacheEntry & entry) const 1.98 + { 1.99 + if (m_accessCount > entry.m_accessCount) return 1; 1.100 + else if (m_accessCount < entry.m_accessCount) return 1; 1.101 + else if (m_lastAccess > entry.m_lastAccess) return 1; 1.102 + else if (m_lastAccess < entry.m_lastAccess) return -1; 1.103 + return 0; 1.104 + } 1.105 + unsigned long long lastAccess() const { return m_lastAccess; }; 1.106 + 1.107 + CLASS_NEW_DELETE; 1.108 +private: 1.109 + 1.110 + size_t m_glyphLength; 1.111 + /** glyph ids resulting from cmap mapping from unicode to glyph before substitution 1.112 + * the length of this array is determined by the position in the SegCachePrefixEntry */ 1.113 + uint16 * m_unicode; 1.114 + /** slots after shapping and positioning */ 1.115 + Slot * m_glyph; 1.116 + int16 * m_attr; 1.117 + byte * m_justs; 1.118 + mutable unsigned long long m_accessCount; 1.119 + mutable unsigned long long m_lastAccess; 1.120 +}; 1.121 + 1.122 +} // namespace graphite2 1.123 + 1.124 +#endif