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

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MiscUtils.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 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
12 namespace Lucene
13 {
14 class LPPAPI MiscUtils
15 {
16 protected:
17 static const uint32_t SINGLE_EXPONENT_MASK;
18 static const uint32_t SINGLE_MANTISSA_MASK;
19 static const uint32_t SINGLE_NAN_BITS;
20
21 static const uint64_t DOUBLE_SIGN_MASK;
22 static const uint64_t DOUBLE_EXPONENT_MASK;
23 static const uint64_t DOUBLE_MANTISSA_MASK;
24 static const uint64_t DOUBLE_NAN_BITS;
25
26 public:
28 static uint64_t getTimeMillis(boost::posix_time::ptime time);
29
31 static uint64_t currentTimeMillis();
32
37 static int32_t getNextSize(int32_t targetSize);
38
41 static int32_t getShrinkSize(int32_t currentSize, int32_t targetSize);
42
48 static int32_t bytesDifference(uint8_t* bytes1, int32_t len1, uint8_t* bytes2, int32_t len2);
49
50 template <typename TYPE>
51 static int32_t hashLucene(TYPE type)
52 {
53 return type->hashCode();
54 }
55
56 template <typename TYPE>
57 static int32_t hashNumeric(TYPE type)
58 {
59 return type;
60 }
61
62 template <typename ITER, typename PRED>
63 static int32_t hashCode(ITER first, ITER last, PRED pred)
64 {
65 int32_t code = 0;
66 for (ITER hash = first; hash != last; ++hash)
67 code = code * 31 + pred(*hash);
68 return code;
69 }
70
72 static int32_t hashCode(const wchar_t* array, int32_t start, int32_t end);
73
75 static int32_t hashCode(const uint8_t* array, int32_t start, int32_t end);
76
78 static int32_t hashCode(bool value);
79
81 template <typename SOURCE, typename DEST>
82 static void arrayCopy(SOURCE source, int32_t sourceOffset, DEST dest, int32_t destOffset, int32_t length)
83 {
84 std::copy(source + sourceOffset, source + sourceOffset + length, dest + destOffset);
85 }
86
88 template <typename DEST, typename FILL>
89 static void arrayFill(DEST dest, int32_t destFrom, int32_t destTo, FILL value)
90 {
91 std::fill(dest + destFrom, dest + destTo, value);
92 }
93
96 static int32_t doubleToIntBits(double value);
97
100 static int32_t doubleToRawIntBits(double value);
101
104 static double intBitsToDouble(int32_t bits);
105
108 static int64_t doubleToLongBits(double value);
109
112 static int64_t doubleToRawLongBits(double value);
113
116 static double longBitsToDouble(int64_t bits);
117
119 static bool isInfinite(double value);
120
122 static bool isNaN(double value);
123
125 template <typename TYPE>
126 static bool typeOf(LuceneObjectPtr object)
127 {
128 return boost::dynamic_pointer_cast<TYPE>(object);
129 }
130
132 static bool equalTypes(LuceneObjectPtr first, LuceneObjectPtr second);
133
135 static int64_t unsignedShift(int64_t num, int64_t shift);
136
138 static int32_t unsignedShift(int32_t num, int32_t shift);
139 };
140 }
141
142 #endif

clucene.sourceforge.net