|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 Eclipse RDF4J contributors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Distribution License v1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: BSD-3-Clause |
| 10 | + *******************************************************************************/ |
| 11 | +package org.eclipse.rdf4j.sail.lmdb; |
| 12 | + |
| 13 | +/** |
| 14 | + * Constants and functions for working with ids encoded into long values. |
| 15 | + */ |
| 16 | +public class ValueIds { |
| 17 | + /** |
| 18 | + * Pointer to an arbitrary value in the value store. This is not used as RDF value. |
| 19 | + */ |
| 20 | + public static final int T_PTR = 0; |
| 21 | + |
| 22 | + /** Reference to a URI */ |
| 23 | + public static final int T_URI = 1; |
| 24 | + /** Reference to a literal */ |
| 25 | + public static final int T_LITERAL = 2; |
| 26 | + /** Reference to a blank node */ |
| 27 | + public static final int T_BNODE = 3; |
| 28 | + /** Reference to a triple */ |
| 29 | + public static final int T_TRIPLE = 4; |
| 30 | + |
| 31 | + // inlined values |
| 32 | + public static final int T_INTEGER = 16; |
| 33 | + public static final int T_DECIMAL = 17; |
| 34 | + public static final int T_FLOAT = 18; |
| 35 | + public static final int T_DATETIME = 19; |
| 36 | + public static final int T_DATETIMESTAMP = 20; |
| 37 | + public static final int T_DATE = 21; |
| 38 | + public static final int T_BOOLEAN = 22; |
| 39 | + public static final int T_SHORTSTRING = 23; |
| 40 | + public static final int T_POSITIVE_INTEGER = 24; |
| 41 | + public static final int T_NEGATIVE_INTEGER = 25; |
| 42 | + public static final int T_NON_NEGATIVE_INTEGER = 26; |
| 43 | + public static final int T_NON_POSITIVE_INTEGER = 27; |
| 44 | + public static final int T_LONG = 28; |
| 45 | + public static final int T_INT = 29; |
| 46 | + public static final int T_SHORT = 30; |
| 47 | + public static final int T_BYTE = 31; |
| 48 | + public static final int T_UNSIGNEDLONG = 32; |
| 49 | + public static final int T_UNSIGNEDINT = 33; |
| 50 | + public static final int T_UNSIGNEDSHORT = 34; |
| 51 | + public static final int T_UNSIGNEDBYTE = 35; |
| 52 | + |
| 53 | + /** |
| 54 | + * Returns the type section of the given id. |
| 55 | + * |
| 56 | + * @param id The id of which the type should be extracted. |
| 57 | + * @return The id's type. |
| 58 | + */ |
| 59 | + public static int getIdType(long id) { |
| 60 | + return (int) ((id >> 1) & 0x3F); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the value section of the given id. |
| 65 | + * |
| 66 | + * @param id The id of which the value should be extracted. |
| 67 | + * @return The id's value. |
| 68 | + */ |
| 69 | + public static long getValue(long id) { |
| 70 | + return id >> 7; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Combines an id type and a value into a single long id. |
| 75 | + * |
| 76 | + * @param idType The id's type. |
| 77 | + * @param value The id's value. |
| 78 | + * @return A composite id. |
| 79 | + */ |
| 80 | + public static long createId(int idType, long value) { |
| 81 | + return value << 7 | idType << 1; |
| 82 | + } |
| 83 | +} |
0 commit comments