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.
Important note: Unless otherwise noted, Lucene uses this class to
represent terms that are encoded as UTF8 bytes in the index. To
convert them to a .NET System.String (which is UTF16), use Utf8ToString().
Using code like 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)!
Inheritance
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
[Serializable]
public sealed class BytesRef : IComparable<BytesRef>, IComparable
Constructors
| Improve this Doc View SourceBytesRef()
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 |
---|---|---|
J2N.Text.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 |
---|---|---|
System.Byte[] | bytes |
BytesRef(Byte[], Int32, Int32)
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 |
---|---|---|
System.Byte[] | bytes | |
System.Int32 | offset | |
System.Int32 | length |
BytesRef(Int32)
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 |
---|---|---|
System.Int32 | capacity |
BytesRef(String)
Initialize the byte[] from the UTF8 bytes for the provided System.String.
Declaration
public BytesRef(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | This must be well-formed unicode text, with no unpaired surrogates. |
Fields
| Improve this Doc View SourceEMPTY_BYTES
An empty byte array for convenience
Declaration
public static readonly byte[] EMPTY_BYTES
Field Value
Type | Description |
---|---|
System.Byte[] |
Properties
| Improve this Doc View SourceBytes
The contents of the BytesRef. Should never be null
.
Declaration
public byte[] Bytes { get; set; }
Property Value
Type | Description |
---|---|
System.Byte[] |
Length
Length of used bytes.
Declaration
public int Length { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Offset
Offset of first valid byte.
Declaration
public int Offset { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
UTF8SortedAsUnicodeComparer
Declaration
public static IComparer<BytesRef> UTF8SortedAsUnicodeComparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IComparer<BytesRef> |
UTF8SortedAsUTF16Comparer
Declaration
[Obsolete("this comparer is only a transition mechanism")]
public static IComparer<BytesRef> UTF8SortedAsUTF16Comparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IComparer<BytesRef> |
Methods
| Improve this Doc View SourceAppend(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.
Declaration
public bool BytesEquals(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other | Another BytesRef, should not be |
Returns
Type | Description |
---|---|
System.Boolean |
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 |
---|---|
System.Object |
See Also
| Improve this Doc View SourceCompareTo(BytesRef)
Unsigned byte order comparison
Declaration
public int CompareTo(BytesRef other)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | other |
Returns
Type | Description |
---|---|
System.Int32 |
CompareTo(Object)
Unsigned byte order comparison
Declaration
public int CompareTo(object other)
Parameters
Type | Name | Description |
---|---|---|
System.Object | other |
Returns
Type | Description |
---|---|
System.Int32 |
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 |
---|---|---|
J2N.Text.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 System.String.
Declaration
public void CopyChars(string text)
Parameters
Type | Name | Description |
---|---|---|
System.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
.
The returned BytesRef will have a length of 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)
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
System.Object | other |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
GetHashCode()
Calculates the hash code as required by Lucene.Net.Index.TermsHash during indexing.
This is currently implemented as MurmurHash3 (32 bit), using the seed from GOOD_FAST_HASH_SEED, but is subject to change from release to release.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Grow(Int32)
Used to grow the reference array.
In general this should not be used as it does not take the offset into account.
Declaration
public void Grow(int newLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | newLength |
IsValid()
Performs internal consistency checks. Always returns true (or throws System.InvalidOperationException)
Declaration
public bool IsValid()
Returns
Type | Description |
---|---|
System.Boolean |
ToString()
Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65]
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
Utf8ToString()
Interprets stored bytes as UTF8 bytes, returning the resulting System.String.
Declaration
public string Utf8ToString()
Returns
Type | Description |
---|---|
System.String |