ImmutableBucket<TValue>
using System;
namespace Stashbox.Utils.Data.Immutable
{
internal class ImmutableBucket<TValue>
{
public static readonly ImmutableBucket<TValue> Empty = new ImmutableBucket<TValue>(Constants.EmptyArray<TValue>());
public readonly int Length;
public readonly TValue[] Repository;
public TValue this[int i] {
get {
return Repository[i];
}
}
public ImmutableBucket(TValue[] repository)
{
Repository = repository;
Length = repository.Length;
}
internal ImmutableBucket<TValue> Add(TValue value)
{
if (Length == 0)
return new ImmutableBucket<TValue>(new TValue[1] {
value
});
TValue[] array = new TValue[Length + 1];
Array.Copy(Repository, array, Length);
array[Length] = value;
return new ImmutableBucket<TValue>(array);
}
}
}