// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later // Copyright 2011, SIL International, All rights reserved.
#pragma once #include <iterator> #include <utility>
#include"inc/Main.h"
namespace graphite2 {
// A read-only packed fast sparse array of uint16 with uint16 keys. // Like most container classes this has capacity and size properties and these // refer to the number of stored entries and the number of addressable entries // as normal. However due the sparse nature the capacity is always <= than the // size. class sparse
{
public: typedef uint16 key_type; typedef uint16 mapped_type; typedef std::pair<const key_type, mapped_type> value_type;
// Find the maximum extent of the key space.
size_t n_values=0; long lastkey = -1; for (I i = attr; i != last; ++i, ++n_values)
{ const typename std::iterator_traits<I>::value_type v = *i; if (v.second == 0) { --n_values; continue; } if (v.first <= lastkey) { m_nchunks = 0; return; }
lastkey = v.first; const key_type k = v.first / SIZEOF_CHUNK; if (k >= m_nchunks) m_nchunks = k+1;
} if (m_nchunks == 0)
{
m_array.map=const_cast<graphite2::sparse::chunk *>(&empty_chunk); return;
}
// coverity[forward_null : FALSE] Since m_array is union and m_array.values is not NULL
chunk * ci = m_array.map;
ci->offset = (m_nchunks*sizeof(chunk) + sizeof(mapped_type)-1)/sizeof(mapped_type);
mapped_type * vi = m_array.values + ci->offset; for (; attr != last; ++attr, ++vi)
{ const typename std::iterator_traits<I>::value_type v = *attr; if (v.second == 0) { --vi; continue; }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.