Created
October 3, 2023 12:54
-
-
Save slimshader/d35a20042f846e51174acff3bdc382ec to your computer and use it in GitHub Desktop.
List for UniMob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Collections.Pooled; | |
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UniMob; | |
| namespace AtomEx | |
| { | |
| public sealed class AtomList<T> : IList<T>, IReadOnlyList<T> | |
| { | |
| private readonly MutableAtom<PooledList<T>> _list = Atom.Value(new PooledList<T>()); | |
| public T this[int index] { get => _list.Value[index]; set => _list.Value[index] = value; } | |
| public int Count => _list.Value.Count; | |
| public bool IsReadOnly => false; | |
| public void Add(T item) | |
| { | |
| _list.Value.Add(item); | |
| _list.Invalidate(); | |
| } | |
| public void Clear() | |
| { | |
| _list.Value.Clear(); | |
| _list.Invalidate(); | |
| } | |
| public bool Contains(T item) => _list.Value.Contains(item); | |
| public void CopyTo(T[] array, int arrayIndex) => _list.Value.CopyTo(array.AsSpan(arrayIndex)); | |
| public int IndexOf(T item) => _list.Value.IndexOf(item); | |
| public void Insert(int index, T item) | |
| { | |
| _list.Value.Insert(index, item); | |
| _list.Invalidate(); | |
| } | |
| public bool Remove(T item) | |
| { | |
| if (_list.Value.Remove(item)) | |
| { | |
| _list.Invalidate(); | |
| return true; | |
| } | |
| return false; | |
| } | |
| public void RemoveAt(int index) | |
| { | |
| _list.Value.RemoveAt(index); | |
| _list.Invalidate(); | |
| } | |
| public IEnumerator<T> GetEnumerator() => _list.Value.GetEnumerator(); | |
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment