The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

parcel Lucy;

/** Read a segment's sort caches.
 */
class Lucy::Index::SortCache inherits Clownfish::Obj {

    String     *field;
    FieldType  *type;
    const void *ords;
    int32_t     doc_max;
    int32_t     cardinality;
    int32_t     ord_width;
    int32_t     null_ord;
    bool        native_ords;

    public inert SortCache*
    init(SortCache *self, String *field, FieldType *type, const void *ords,
         int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
         int32_t ord_width);

    /** Return the value for ordinal <code>ord</code>, or NULL if the value
     * for <code>ord</code> is NULL.
     */
    public abstract nullable incremented Obj*
    Value(SortCache *self, int32_t ord);

    public const void*
    Get_Ords(SortCache *self);

    public int32_t
    Get_Cardinality(SortCache *self);

    public int32_t
    Get_Ord_Width(SortCache *self);

    public int32_t
    Get_Null_Ord(SortCache *self);

    public int32_t
    Ordinal(SortCache *self, int32_t doc_id);

    /** Attempt to find the ordinal of the supplied <code>term</code>.  If the
     * term cannot be found, return the ordinal of the term that would appear
     * immediately before it in sort order.
     *
     * @return an integer between -1 and the highest ordinal.
     */
    public int32_t
    Find(SortCache *self, Obj *term = NULL);

    /** Early versions of SortCache had a bug where ords were written using
     * native byte order rather than big-endian byte order.  The "native_ords"
     * setting indicates whether this SortCache has such a bug.
     */
    void
    Set_Native_Ords(SortCache *self, bool native_ords);

    bool
    Get_Native_Ords(SortCache *self);

    public void
    Destroy(SortCache *self);
}