Table of Contents

Class Mapper

Namespace
Rinku.Querying
Assembly
Rinku.dll

Maps case insensitive names to stable indexes. Create a new mapper when the key set changes. Use GetKey(int) or GetSameKey(string) when reference comparison is useful.

public abstract class Mapper : IReadOnlyDictionary<string, int>, IReadOnlyCollection<KeyValuePair<string, int>>, IEnumerable<KeyValuePair<string, int>>, IEnumerable, IDisposable
Inheritance
Mapper
Implements
Inherited Members
Extension Methods

Constructors

Mapper(string[])

Maps case insensitive names to stable indexes. Create a new mapper when the key set changes. Use GetKey(int) or GetSameKey(string) when reference comparison is useful.

protected Mapper(string[] Keys)

Parameters

Keys string[]

Fields

EmptyMapper

Instance of a Mapper without any keys.

public static readonly Mapper EmptyMapper

Field Value

Mapper

_keys

The names available to a custom mapper.

protected string[] _keys

Field Value

string[]

Properties

Count

Gets the number of unique keys defined in this schema.

public int Count { get; }

Property Value

int

this[ReadOnlySpan<char>]

Returns the stable index associated with the provided key.

public int this[ReadOnlySpan<char> key] { get; }

Parameters

key ReadOnlySpan<char>

The case-insensitive key to locate.

Property Value

int

The zero-based index of the key if it exists, otherwise -1.

this[string]

Returns the stable index associated with the provided key.

public int this[string key] { get; }

Parameters

key string

The case-insensitive key to locate.

Property Value

int

The zero-based index of the key if it exists, otherwise -1.

Keys

Gets the unique keys held by this mapper as a ReadOnlySpan<T>.

public ReadOnlySpan<string> Keys { get; }

Property Value

ReadOnlySpan<string>

Values

Gets an enumerable collection that contains the values in the read-only dictionary.

public IEnumerable<int> Values { get; }

Property Value

IEnumerable<int>

An enumerable collection that contains the values in the read-only dictionary.

Methods

ContainsKey(ReadOnlySpan<char>)

public bool ContainsKey(ReadOnlySpan<char> key)

Parameters

key ReadOnlySpan<char>

Returns

bool

ContainsKey(string)

Determines whether the read-only dictionary contains an element that has the specified key.

public bool ContainsKey(string key)

Parameters

key string

The key to locate.

Returns

bool

true if the read-only dictionary contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

Dispose()

Releases resources owned by this mapper. This method can be called more than once.

public virtual void Dispose()

DisposeUnmanaged()

Override this method to release resources owned by a custom mapper.

protected abstract void DisposeUnmanaged()

~Mapper()

[ExcludeFromCodeCoverage]
protected ~Mapper()

GetEmptyMapper()

Provides a shared schema for instances requiring zero keys.

public static Mapper GetEmptyMapper()

Returns

Mapper

A singleton Mapper containing no keys.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<string, int>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, int>>

An enumerator that can be used to iterate through the collection.

GetIndex(char, string)

Finds the index after adding one character before value.

public int GetIndex(char prependChar, string value)

Parameters

prependChar char
value string

Returns

int

GetIndex(ReadOnlySpan<char>)

Returns the stable index associated with the provided key.

public abstract int GetIndex(ReadOnlySpan<char> key)

Parameters

key ReadOnlySpan<char>

The case-insensitive key to locate.

Returns

int

The zero-based index of the key if it exists, otherwise -1.

GetIndex(string)

Returns the stable index associated with the provided key.

public abstract int GetIndex(string key)

Parameters

key string

The case-insensitive key to locate.

Returns

int

The zero-based index of the key if it exists, otherwise -1.

GetKey(int)

Gets the stored name at the given index.

public string GetKey(int ind)

Parameters

ind int

The index to read.

Returns

string

The stored string instance.

GetMapper(IEnumerable<string>)

Creates a mapper for the supplied names.

public static Mapper GetMapper(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

The collection of keys to index.

Returns

Mapper

A mapper that preserves the first occurrence of each name.

Remarks

Input order is preserved. If duplicate keys (case-insensitive) are present, only the first occurrence is stored, and its position becomes the fixed index for that key.

GetMapper(params Span<string>)

Creates a mapper for the supplied names.

public static Mapper GetMapper(params Span<string> keys)

Parameters

keys Span<string>

A span of keys used to define the schema.

Returns

Mapper

A mapper that preserves the first occurrence of each name.

Remarks

Input order is preserved. If duplicate keys (case-insensitive) are present, only the first occurrence is stored, and its position becomes the fixed index for that key.

GetOneKeyMapper(string)

Creates a mapper containing one name at index zero.

public static Mapper GetOneKeyMapper(string key)

Parameters

key string

The sole key in the schema.

Returns

Mapper

A mapper containing the supplied name.

GetSameKey(ReadOnlySpan<char>)

Gets the stored string instance that matches the name.

public string GetSameKey(ReadOnlySpan<char> key)

Parameters

key ReadOnlySpan<char>

The name to find.

Returns

string

The stored string instance or null when no name matches.

GetSameKey(string)

Gets the stored string instance that matches the name.

public string GetSameKey(string key)

Parameters

key string

The name to find.

Returns

string

The stored string instance or null when no name matches.

GetTwoKeyMapper(string, string)

Creates a mapper containing up to two names.

public static Mapper GetTwoKeyMapper(string key1, string key2)

Parameters

key1 string

The key to be assigned to index 0.

key2 string

The key to be assigned to index 1.

Returns

Mapper

A mapper containing the distinct supplied names.

Remarks

If the keys are identical (case-insensitive), this returns a single-key mapper to ensure the index remains stable at 0.

IsAllAscii(string[])

Checks if all strings in the array contain only ASCII characters.

public static bool IsAllAscii(string[] keys)

Parameters

keys string[]

Returns

bool

TryGetValue(ReadOnlySpan<char>, out int)

public bool TryGetValue(ReadOnlySpan<char> key, out int value)

Parameters

key ReadOnlySpan<char>
value int

Returns

bool

TryGetValue(string, out int)

Gets the value that is associated with the specified key.

public bool TryGetValue(string key, out int value)

Parameters

key string

The key to locate.

value int

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.