torima toritori
This commit is contained in:
parent
e58421b2c2
commit
e08cce94b0
15
src/ObservableCollections/ObservableHashSet.cs
Normal file
15
src/ObservableCollections/ObservableHashSet.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ObservableCollections
|
||||||
|
{
|
||||||
|
public sealed partial class ObservableHashSet<T>
|
||||||
|
{
|
||||||
|
//// TODO:not yet
|
||||||
|
//readonly LinkedList<T> list;
|
||||||
|
|
||||||
|
//public ObservableHashSet(LinkedList<T> list)
|
||||||
|
//{
|
||||||
|
// this.list = list;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
111
src/ObservableCollections/ObservableLinkedList.Views.cs
Normal file
111
src/ObservableCollections/ObservableLinkedList.Views.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
namespace ObservableCollections
|
||||||
|
{
|
||||||
|
public sealed partial class ObservableLinkedList<T> : IReadOnlyCollection<T>, IObservableCollection<LinkedListNode<T>>
|
||||||
|
{
|
||||||
|
public ISynchronizedView<LinkedListNode<T>, TView> CreateView<TView>(Func<LinkedListNode<T>, TView> transform, bool reverse = false)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISynchronizedView<LinkedListNode<T>, TView> CreateSortedView<TKey, TView>(Func<LinkedListNode<T>, TKey> identitySelector, Func<LinkedListNode<T>, TView> transform, IComparer<LinkedListNode<T>> comparer) where TKey : notnull
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISynchronizedView<LinkedListNode<T>, TView> CreateSortedView<TKey, TView>(Func<LinkedListNode<T>, TKey> identitySelector, Func<LinkedListNode<T>, TView> transform, IComparer<TView> viewComparer) where TKey : notnull
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class View<TView> : ISynchronizedView<LinkedListNode<T>, TView>
|
||||||
|
{
|
||||||
|
readonly ObservableLinkedList<T> source;
|
||||||
|
readonly LinkedList<(LinkedListNode<T>, TView)> list;
|
||||||
|
readonly Func<LinkedListNode<T>, TView> selector;
|
||||||
|
|
||||||
|
public View(ObservableLinkedList<T> source)
|
||||||
|
{
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
|
lock (source.SyncRoot)
|
||||||
|
{
|
||||||
|
// TODO:get map
|
||||||
|
source.CollectionChanged += SourceCollectionChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public object SyncRoot => throw new NotImplementedException();
|
||||||
|
public event NotifyCollectionChangedEventHandler<LinkedListNode<T>>? RoutingCollectionChanged;
|
||||||
|
public event Action<NotifyCollectionChangedAction>? CollectionStateChanged;
|
||||||
|
|
||||||
|
|
||||||
|
public int Count => throw new NotImplementedException();
|
||||||
|
|
||||||
|
|
||||||
|
public void AttachFilter(ISynchronizedViewFilter<LinkedListNode<T>, TView> filter)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<(LinkedListNode<T> Value, TView View)> GetEnumerator()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetFilter(Action<LinkedListNode<T>, TView>? resetAction)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public INotifyCollectionChangedSynchronizedView<LinkedListNode<T>, TView> WithINotifyCollectionChanged()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SourceCollectionChanged(in NotifyCollectionChangedEventArgs<LinkedListNode<T>> e)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
switch (e.Action)
|
||||||
|
{
|
||||||
|
case NotifyCollectionChangedAction.Add:
|
||||||
|
{
|
||||||
|
// AddAfter
|
||||||
|
if (e.OldItem != null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Remove:
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Replace:
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Move:
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Reset:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,143 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
namespace ObservableCollections
|
namespace ObservableCollections
|
||||||
{
|
{
|
||||||
public sealed partial class ObservableLinkedList<T>
|
// TODO:Remove this???
|
||||||
|
public sealed partial class ObservableLinkedList<T> : IReadOnlyCollection<T>, IObservableCollection<LinkedListNode<T>>
|
||||||
{
|
{
|
||||||
// TODO:not yet
|
|
||||||
readonly LinkedList<T> list;
|
readonly LinkedList<T> list;
|
||||||
|
public readonly object SyncRoot = new object();
|
||||||
|
|
||||||
public ObservableLinkedList(LinkedList<T> list)
|
public event NotifyCollectionChangedEventHandler<LinkedListNode<T>>? CollectionChanged;
|
||||||
|
|
||||||
|
public ObservableLinkedList()
|
||||||
{
|
{
|
||||||
this.list = list;
|
this.list = new LinkedList<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableLinkedList(IEnumerable<T> collection)
|
||||||
|
{
|
||||||
|
this.list = new LinkedList<T>(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: First, Last
|
||||||
|
// Find, FindLast
|
||||||
|
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
return list.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedListNode<T> AddFirst(T item)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var node = list.AddFirst(item);
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Add(node, 0));
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedListNode<T> AddLast(T item)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var index = list.Count;
|
||||||
|
var node = list.AddLast(item);
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Add(node, index));
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedListNode<T> AddBefore(LinkedListNode<T> node, T value)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var newNode = list.AddBefore(node, value);
|
||||||
|
|
||||||
|
// list.
|
||||||
|
|
||||||
|
// special event, oldItem is target, newStartingIndex:-1 = before
|
||||||
|
var ev = new NotifyCollectionChangedEventArgs<LinkedListNode<T>>(
|
||||||
|
NotifyCollectionChangedAction.Add, isSingleItem: true,
|
||||||
|
newItem: newNode, oldItem: node, newStartingIndex: -1);
|
||||||
|
|
||||||
|
CollectionChanged?.Invoke(ev);
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedListNode<T> AddAfter(LinkedListNode<T> node, T value)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var newNode = list.AddAfter(node, value);
|
||||||
|
|
||||||
|
// special event, oldItem is target, newStartingIndex:1 = after
|
||||||
|
var ev = new NotifyCollectionChangedEventArgs<LinkedListNode<T>>(
|
||||||
|
NotifyCollectionChangedAction.Add, isSingleItem: true,
|
||||||
|
newItem: newNode, oldItem: node, newStartingIndex: 1);
|
||||||
|
|
||||||
|
CollectionChanged?.Invoke(ev);
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveLast()
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var last = list.Last;
|
||||||
|
list.RemoveLast();
|
||||||
|
if (last != null)
|
||||||
|
{
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(last, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveFirst()
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var first = list.First;
|
||||||
|
list.RemoveFirst();
|
||||||
|
if (first != null)
|
||||||
|
{
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(first, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(LinkedListNode<T> item)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
list.Remove(item);
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(item, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: GetEnumerator
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using ObservableCollections.Internal;
|
using ObservableCollections.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -93,18 +95,70 @@ namespace ObservableCollections
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dequeue()
|
public T Dequeue()
|
||||||
{
|
{
|
||||||
// this.queue.
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var index = queue.Count - 1;
|
||||||
|
var v = queue.Dequeue();
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<T>.Remove(v, index));
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryDequeue
|
public bool TryDequeue([MaybeNullWhen(false)] out T result)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var index = queue.Count - 1;
|
||||||
|
if (queue.TryDequeue(out result))
|
||||||
|
{
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<T>.Remove(result, index));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DequeueRange
|
public void DequeueRange(int count)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var startIndex = queue.Count - count;
|
||||||
|
|
||||||
|
var dest = ArrayPool<T>.Shared.Rent(count);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
dest[0] = queue.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<T>.Remove(dest.AsSpan(0, count), startIndex));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ArrayPool<T>.Shared.Return(dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DequeueRange(Span<T> dest)
|
||||||
|
{
|
||||||
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
var count = queue.Count;
|
||||||
|
var destCount = dest.Length;
|
||||||
|
for (int i = 0; i < dest.Length; i++)
|
||||||
|
{
|
||||||
|
dest[0] = queue.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
|
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<T>.Remove(dest, count - queue.Count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user