Class BytesRef
Represents byte[], as a slice (offset + length) into an
existing byte[]. The Bytes property should never be null
;
use EMPTY_BYTES if necessary.
new String(bytes, offset, length)
to do this
is wrong, as it does not respect the correct character set
and may return wrong results (depending on the platform's defaults)!
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
[Serializable]
public sealed class BytesRef : IComparable<BytesRef>, IComparable, IEquatable<BytesRef>
Constructors
BytesRef()
Create a BytesRef with EMPTY_BYTES
Declaration
public BytesRef()
BytesRef(ICharSequence)
Initialize the byte[] from the UTF8 bytes for the provided J2N.Text.ICharSequence.
Declaration
public BytesRef(ICharSequence text)
Parameters
Type | Name | Description |
---|---|---|
ICharSequence | text | This must be well-formed unicode text, with no unpaired surrogates. |
BytesRef(byte[])
This instance will directly reference bytes
w/o making a copy.
bytes
should not be null
.
Declaration
public BytesRef(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytes |
BytesRef(byte[], int, int)
This instance will directly reference bytes
w/o making a copy.
bytes
should not be null
.
Declaration
public BytesRef(byte[] bytes, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
byte[] | bytes | |
int | offset | |
int | length |
BytesRef(int)
Create a BytesRef pointing to a new array of size capacity
.
Offset and length will both be zero.
Declaration
public BytesRef(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity |
BytesRef(string)
Initialize the byte[] from the UTF8 bytes for the provided string.
Declaration
public BytesRef(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | This must be well-formed unicode text, with no unpaired surrogates. |
Fields
EMPTY_BYTES
An empty byte array for convenience
Declaration
public static readonly byte[] EMPTY_BYTES
Field Value
Type | Description |
---|---|
byte[] |
Properties
Bytes
The contents of the BytesRef. Should never be null
.
Declaration
public byte[] Bytes { get; set; }
Property Value
Type | Description |
---|---|
byte[] |
Length
Length of used bytes.
Declaration
public int Length { get; set; }
Property Value
Type | Description |
---|---|
int |
Offset
Offset of first valid byte.
Declaration
public int Offset { get; set; }
Property Value
Type | Description |
---|---|
int |
UTF8SortedAsUTF16Comparer
Represents byte[], as a slice (offset + length) into an
existing byte[]. The Bytes property should never be null
;
use EMPTY_BYTES if necessary.
new String(bytes, offset, length)
to do this
is wrong, as it does not respect the correct character set
and may return wrong results (depending on the platform's defaults)!
Declaration
[Obsolete("this comparer is only a transition mechanism")]
public static IComparer<BytesRef> UTF8SortedAsUTF16Comparer { get; }
Property Value
Type | Description |
---|---|
IComparer<BytesRef> |
UTF8SortedAsUnicodeComparer
Represents byte[], as a slice (offset + length) into an
existing byte[]. The Bytes property should never be null
;
use EMPTY_BYTES if necessary.
new String(bytes, offset, length)
to do this
is wrong, as it does not respect the correct character set
and may return wrong results (depending on the platform's defaults)!
Declaration
public static IComparer<BytesRef> UTF8SortedAsUnicodeComparer { get; }
Property Value
Type | Description |
---|---|
IComparer<BytesRef> |
Methods
Append(BytesRef)
Appends the bytes from the given BytesRef
NOTE: if this would exceed the array size, this method creates a new reference array.Declaration
public void Append(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other |
BytesEquals(BytesRef)
Expert: Compares the bytes against another BytesRef,
returning true
if the bytes are equal.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public bool BytesEquals(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other | Another BytesRef, should not be |
Returns
Type | Description |
---|---|
bool |
Clone()
Returns a shallow clone of this instance (the underlying bytes are not copied and will be shared by both the returned object and this object.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
object |
See Also
CompareTo(BytesRef)
Unsigned byte order comparison
Declaration
public int CompareTo(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other |
Returns
Type | Description |
---|---|
int |
CompareTo(object)
Unsigned byte order comparison
Declaration
public int CompareTo(object other)
Parameters
Type | Name | Description |
---|---|---|
object | other |
Returns
Type | Description |
---|---|
int |
CopyBytes(BytesRef)
Copies the bytes from the given BytesRef
NOTE: if this would exceed the array size, this method creates a new reference array.Declaration
public void CopyBytes(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other |
CopyChars(ICharSequence)
Copies the UTF8 bytes for this J2N.Text.ICharSequence.
Declaration
public void CopyChars(ICharSequence text)
Parameters
Type | Name | Description |
---|---|---|
ICharSequence | text | Must be well-formed unicode text, with no unpaired surrogates or invalid UTF16 code units. |
CopyChars(string)
Copies the UTF8 bytes for this string.
Declaration
public void CopyChars(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | Must be well-formed unicode text, with no unpaired surrogates or invalid UTF16 code units. |
DeepCopyOf(BytesRef)
Creates a new BytesRef that points to a copy of the bytes from
other
.
other.Length
and an offset of zero.
Declaration
public static BytesRef DeepCopyOf(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other |
Returns
Type | Description |
---|---|
BytesRef |
Equals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
object | other |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
GetHashCode()
Calculates the hash code as required by TermsHash during indexing.
This is currently implemented as MurmurHash3 (32 bit), using the seed from GoodFastHashSeed, but is subject to change from release to release.Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
Grow(int)
Used to grow the reference array.
In general this should not be used as it does not take the offset into account.Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public void Grow(int newLength)
Parameters
Type | Name | Description |
---|---|---|
int | newLength |
IsValid()
Performs internal consistency checks. Always returns true (or throws InvalidOperationException)
Declaration
public bool IsValid()
Returns
Type | Description |
---|---|
bool |
ToString()
Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65]
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
Utf8ToString()
Interprets stored bytes as UTF8 bytes, returning the resulting string.
Declaration
public string Utf8ToString()
Returns
Type | Description |
---|---|
string |