Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
MiscUtils.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef MISCUTILS_H
8#define MISCUTILS_H
9
10#include "Lucene.h"
11
12namespace Lucene {
13
14class LPPAPI MiscUtils {
15protected:
16 static const uint32_t SINGLE_EXPONENT_MASK;
17 static const uint32_t SINGLE_MANTISSA_MASK;
18 static const uint32_t SINGLE_NAN_BITS;
19
20 static const uint64_t DOUBLE_SIGN_MASK;
21 static const uint64_t DOUBLE_EXPONENT_MASK;
22 static const uint64_t DOUBLE_MANTISSA_MASK;
23 static const uint64_t DOUBLE_NAN_BITS;
24
25public:
27 static uint64_t getTimeMillis(boost::posix_time::ptime time);
28
30 static uint64_t currentTimeMillis();
31
36 static int32_t getNextSize(int32_t targetSize);
37
40 static int32_t getShrinkSize(int32_t currentSize, int32_t targetSize);
41
47 static int32_t bytesDifference(uint8_t* bytes1, int32_t len1, uint8_t* bytes2, int32_t len2);
48
49 template <typename TYPE>
50 static int32_t hashLucene(TYPE type) {
51 return type->hashCode();
52 }
53
54 template <typename TYPE>
55 static int32_t hashNumeric(TYPE type) {
56 return type;
57 }
58
59 template <typename ITER, typename PRED>
60 static int32_t hashCode(ITER first, ITER last, PRED pred) {
61 int32_t code = 0;
62 for (ITER hash = first; hash != last; ++hash) {
63 code = code * 31 + pred(*hash);
64 }
65 return code;
66 }
67
69 static int32_t hashCode(const wchar_t* array, int32_t start, int32_t end);
70
72 static int32_t hashCode(const uint8_t* array, int32_t start, int32_t end);
73
75 static int32_t hashCode(bool value);
76
78 template <typename SOURCE, typename DEST>
79 static void arrayCopy(SOURCE source, int32_t sourceOffset, DEST dest, int32_t destOffset, int32_t length) {
80 std::copy(source + sourceOffset, source + sourceOffset + length, dest + destOffset);
81 }
82
84 template <typename DEST, typename FILL>
85 static void arrayFill(DEST dest, int32_t destFrom, int32_t destTo, FILL value) {
86 std::fill(dest + destFrom, dest + destTo, value);
87 }
88
91 static int32_t doubleToIntBits(double value);
92
95 static int32_t doubleToRawIntBits(double value);
96
99 static double intBitsToDouble(int32_t bits);
100
103 static int64_t doubleToLongBits(double value);
104
107 static int64_t doubleToRawLongBits(double value);
108
111 static double longBitsToDouble(int64_t bits);
112
114 static bool isInfinite(double value);
115
117 static bool isNaN(double value);
118
120 template <typename TYPE>
121 static bool typeOf(const LuceneObjectPtr& object) {
122 return boost::dynamic_pointer_cast<TYPE>(object).get() != NULL;
123 }
124
126 static bool equalTypes(const LuceneObjectPtr& first, const LuceneObjectPtr& second);
127
129 static int64_t unsignedShift(int64_t num, int64_t shift);
130
132 static int32_t unsignedShift(int32_t num, int32_t shift);
133};
134
135inline int64_t MiscUtils::unsignedShift(int64_t num, int64_t shift) {
136 return (shift & 0x3f) == 0 ? num : (((uint64_t)num >> 1) & 0x7fffffffffffffffLL) >> ((shift & 0x3f) - 1);
137}
138
139inline int32_t MiscUtils::unsignedShift(int32_t num, int32_t shift) {
140 return (shift & 0x1f) == 0 ? num : (((uint32_t)num >> 1) & 0x7fffffff) >> ((shift & 0x1f) - 1);
141}
142
143}
144
145#endif
Definition MiscUtils.h:14
static bool isNaN(double value)
Returns true if this Double value is a Not-a-Number (NaN), false otherwise.
static int32_t hashCode(bool value)
Returns hash code of given boolean.
static int64_t doubleToRawLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-poi...
static int32_t hashNumeric(TYPE type)
Definition MiscUtils.h:55
static uint64_t currentTimeMillis()
Returns the current time in milliseconds.
static const uint32_t SINGLE_MANTISSA_MASK
Definition MiscUtils.h:17
static const uint64_t DOUBLE_SIGN_MASK
Definition MiscUtils.h:20
static int64_t doubleToLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-poi...
static void arrayFill(DEST dest, int32_t destFrom, int32_t destTo, FILL value)
Fill buffer with given element.
Definition MiscUtils.h:85
static bool typeOf(const LuceneObjectPtr &object)
Return whether given Lucene object is of a specified type.
Definition MiscUtils.h:121
static int32_t hashCode(const wchar_t *array, int32_t start, int32_t end)
Returns hash of chars in range start (inclusive) to end (inclusive)
static int32_t getShrinkSize(int32_t currentSize, int32_t targetSize)
Only reallocate if we are "substantially" smaller. This saves us from "running hot" (constantly makin...
static int32_t doubleToIntBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-poi...
static int32_t hashCode(const uint8_t *array, int32_t start, int32_t end)
Returns hash of bytes in range start (inclusive) to end (inclusive)
static int32_t hashCode(ITER first, ITER last, PRED pred)
Definition MiscUtils.h:60
static void arrayCopy(SOURCE source, int32_t sourceOffset, DEST dest, int32_t destOffset, int32_t length)
Copy elements from on buffer to another.
Definition MiscUtils.h:79
static bool isInfinite(double value)
Returns true if the specified number is infinitely large in magnitude, false otherwise.
static int32_t bytesDifference(uint8_t *bytes1, int32_t len1, uint8_t *bytes2, int32_t len2)
Compares two byte[] arrays, element by element, and returns the number of elements common to both arr...
static const uint32_t SINGLE_EXPONENT_MASK
Definition MiscUtils.h:16
static int32_t hashLucene(TYPE type)
Definition MiscUtils.h:50
static int32_t getNextSize(int32_t targetSize)
This over-allocates proportional to the list size, making room for additional growth....
static const uint64_t DOUBLE_NAN_BITS
Definition MiscUtils.h:23
static const uint64_t DOUBLE_MANTISSA_MASK
Definition MiscUtils.h:22
static const uint64_t DOUBLE_EXPONENT_MASK
Definition MiscUtils.h:21
static int32_t doubleToRawIntBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-poi...
static const uint32_t SINGLE_NAN_BITS
Definition MiscUtils.h:18
static double longBitsToDouble(int64_t bits)
Returns the double value corresponding to a given bit representation. The argument is considered to b...
static int64_t unsignedShift(int64_t num, int64_t shift)
Perform unsigned right-shift (left bits are zero filled)
Definition MiscUtils.h:135
static bool equalTypes(const LuceneObjectPtr &first, const LuceneObjectPtr &second)
Return whether given Lucene objects are of equal type.
static uint64_t getTimeMillis(boost::posix_time::ptime time)
Return given time in milliseconds.
static double intBitsToDouble(int32_t bits)
Returns the float value corresponding to a given bit representation. The argument is considered to be...
Definition AbstractAllTermDocs.h:12
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition LuceneTypes.h:539

clucene.sourceforge.net