Skip to content

Beta #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 8, 2018
Merged

Beta #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Advanced.Algorithms.Tests/Distributed/AsyncQueue_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void AsyncQueue_Test()
//multi-threaded async producer
tasks.AddRange(Enumerable.Range(1, testDataCount).Select(async x =>
{
await Task.Delay(random.Next(0, 2));
await Task.Delay(random.Next(0, 1));

await producerLock.WaitAsync();

Expand All @@ -46,7 +46,7 @@ public void AsyncQueue_Test()
//multi-threaded async consumer
tasks.AddRange(Enumerable.Range(1, testDataCount).Select(async x =>
{
await Task.Delay(random.Next(0, 2));
await Task.Delay(random.Next(0, 1));

await consumerLock.WaitAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void AddEdge(T source, T dest)
}

/// <summary>
/// Remove an existing edge between source & destination.
/// Remove an existing edge between source and destination.
/// Time complexity: O(1).
/// </summary>
public void RemoveEdge(T source, T dest)
Expand Down Expand Up @@ -218,7 +218,7 @@ public IEnumerator<T> GetEnumerator()
}

/// <summary>
/// DiGraph vertex.
/// DiGraph vertex for adjacency list Graph implementation.
/// IEnumerable enumerates all the outgoing edge destination vertices.
/// </summary>
public class DiGraphVertex<T> : IEnumerable<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public GraphVertex<T> AddVertex(T value)
/// Remove an existing vertex from this graph.
/// Time complexity: O(V) where V is the number of vertices.
/// </summary>
/// <param name="vertex"></param>
public void RemoveVertex(T vertex)
{
if (vertex == null)
Expand Down Expand Up @@ -188,7 +187,7 @@ public IEnumerator<T> GetEnumerator()
}

/// <summary>
/// Graph vertex.
/// Graph vertex for adjacency list Graph implementation.
/// IEnumerable enumerates all the outgoing edge destination vertices.
/// </summary>
public class GraphVertex<T> : IEnumerable<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public IEnumerator<T> GetEnumerator()
}

/// <summary>
/// A weighted graph vertex.
/// A weighted graph vertex for adjacency list Graph implementation.
/// IEnumerable enumerates all the outgoing edge destination vertices.
/// </summary>
public class WeightedDiGraphVertex<T, TW> : IEnumerable<T> where TW : IComparable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public IEnumerator<T> GetEnumerator()
return Vertices.Select(x => x.Key).GetEnumerator();
}
}

/// <summary>
/// A weighted graph vertex.
/// A weighted graph vertex for adjacency list Graph implementation.
/// IEnumerable enumerates all the outgoing edge destination vertices.
/// </summary>
public class WeightedGraphVertex<T, TW> : IEnumerable<T> where TW : IComparable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void AddVertex(T value)
/// Remove an existing vertex from graph
/// Time complexity: O(V) where V is the number of vertices.
/// </summary>
/// <param name="value"></param>
public void RemoveVertex(T value)
{
if (value == null)
Expand Down Expand Up @@ -112,8 +111,6 @@ public void RemoveVertex(T value)
/// add an edge from source to destination vertex
/// Time complexity: O(1).
/// </summary>
/// <param name="source"></param>
/// <param name="dest"></param>
public void AddEdge(T source, T dest)
{
if (source == null || dest == null)
Expand All @@ -137,7 +134,7 @@ public void AddEdge(T source, T dest)
}

/// <summary>
/// remove an existing edge between source & destination
/// remove an existing edge between source and destination
/// Time complexity: O(1).
/// </summary>
public void RemoveEdge(T source, T dest)
Expand Down
15 changes: 13 additions & 2 deletions Advanced.Algorithms/DataStructures/Graph/AdjacencyMatrix/Graph.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix
{
Expand All @@ -9,7 +10,7 @@ namespace Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix
/// A directed graph implementation using dynamically growinng/shrinking adjacency matrix array.
/// IEnumerable enumerates all vertices.
/// </summary>
public class Graph<T>
public class Graph<T> : IEnumerable<T>
{
public int VerticesCount => usedSize;

Expand Down Expand Up @@ -135,7 +136,7 @@ public void AddEdge(T source, T dest)
}

/// <summary>
/// Remove an existing edge between source & destination.
/// Remove an existing edge between source and destination.
/// Time complexity: O(1).
/// </summary>
public void RemoveEdge(T source, T dest)
Expand Down Expand Up @@ -298,5 +299,15 @@ private void halfMatrixSize()
reverseVertexIndices = newReverseIndices;
maxSize /= 2;
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public IEnumerator<T> GetEnumerator()
{
return vertexIndices.Select(x => x.Key).GetEnumerator();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix
{
/// <summary>
/// A weighted graph implementation using dynamically growinng/shrinking adjacency matrix array.
/// IEnumerable enumerates all vertices.
/// </summary>
public class WeightedDiGraph<T, TW> where TW : IComparable
public class WeightedDiGraph<T, TW> : IEnumerable<T> where TW : IComparable
{
public int VerticesCount => usedSize;

Expand Down Expand Up @@ -301,5 +303,15 @@ private void halfMatrixSize()
reverseVertexIndices = newReverseIndices;
maxSize /= 2;
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public IEnumerator<T> GetEnumerator()
{
return vertexIndices.Select(x => x.Key).GetEnumerator();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix
{
/// <summary>
/// A weighted graph implementation using dynamically growinng/shrinking adjacency matrix array.
/// IEnumerable enumerates all vertices.
/// </summary>
public class WeightedGraph<T, TW> where TW : IComparable
public class WeightedGraph<T, TW> : IEnumerable<T> where TW : IComparable
{
public int VerticesCount => usedSize;

Expand Down Expand Up @@ -288,5 +290,15 @@ private void halfMatrixSize()
reverseVertexIndices = newReverseIndices;
maxSize /= 2;
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public IEnumerator<T> GetEnumerator()
{
return vertexIndices.Select(x => x.Key).GetEnumerator();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void Merge(BinomialMaxHeap<T> binomialHeap)
/// <summary>
/// Time complexity: O(log(n)).
/// </summary>
/// <returns></returns>
public T PeekMax()
{
if (heapForest.Head == null)
Expand Down Expand Up @@ -184,7 +183,7 @@ private void meld()
cur = next;
next = cur.Next;
}
//degress of cur & next are same
//degress of cur and next are same
else
{
//case 2 next degree equals next-next degree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ private void cut(FibornacciHeapNode<T> node)
/// <summary>
/// Merges the given fibornacci node list to current Forest
/// </summary>
/// <param name="headPointer"></param>
private void mergeForests(FibornacciHeapNode<T> headPointer)
{
var current = headPointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void Merge(BinomialMinHeap<T> binomialHeap)
/// <summary>
/// Time complexity: O(log(n)).
/// </summary>
/// <returns></returns>
public T PeekMin()
{
if (heapForest.Head == null)
Expand Down Expand Up @@ -184,7 +183,7 @@ private void meld()
cur = next;
next = cur.Next;
}
//degress of cur & next are same
//degress of cur and next are same
else
{
//case 2 next degree equals next-next degree
Expand Down Expand Up @@ -228,7 +227,7 @@ private void meld()

/// <summary>
/// Merges the given sorted forest to current sorted Forest
/// & returns the last inserted node (pointer required for decrement-key)
/// and returns the last inserted node (pointer required for decrement-key)
/// </summary>
private void mergeSortedForests(DoublyLinkedList<BinomialHeapNode<T>> newHeapForest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ private void cut(FibornacciHeapNode<T> node)
/// <summary>
/// Merges the given fibornacci node list to current Forest
/// </summary>
/// <param name="headPointer"></param>
private void mergeForests(FibornacciHeapNode<T> headPointer)
{
var current = headPointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public T DeleteFirst()
/// Delete tail node.
/// Time complexity: O(1)
/// </summary>
/// <returns></returns>
///
public T DeleteLast()
{
if (Tail == null)
Expand Down Expand Up @@ -344,7 +344,7 @@ internal void Union(DoublyLinkedList<T> newList)
/// <summary>
/// Time complexity: O(1).
/// </summary>
/// <returns></returns>
///
public bool IsEmpty() => Head == null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void InsertLast(T data)
/// <summary>
/// Time complexity: O(1).
/// </summary>
/// <returns></returns>
public T DeleteFirst()
{
if (Head == null)
Expand All @@ -69,7 +68,6 @@ public T DeleteFirst()
/// <summary>
/// Time complexity: O(n).
/// </summary>
/// <returns></returns>
public T DeleteLast()
{
if (Head == null)
Expand Down
2 changes: 0 additions & 2 deletions Advanced.Algorithms/DataStructures/List/ArrayList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public ArrayList(IEnumerable<T> initial)
/// Time complexity: O(1).
/// </summary>
/// <param name="index">The index to write or read.</param>
/// <returns></returns>
public T this[int index]
{
get => itemAt(index);
Expand All @@ -75,7 +74,6 @@ private T itemAt(int i)
/// Add a new item to this array list.
/// Time complexity: O(1) amortized.
/// </summary>
/// <param name="item"></param>
public void Add(T item)
{
grow();
Expand Down
2 changes: 0 additions & 2 deletions Advanced.Algorithms/DataStructures/List/SkipList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public SkipList(int maxHeight = 32)
/// If item is not found default value of T will be returned.
/// Time complexity: O(log(n)).
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public T Find(T value)
{
var current = Head;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void Enqueue(T item)
/// <summary>
/// Time complexity:O(log(n)).
/// </summary>
/// <returns></returns>
public T Dequeue()
{
return maxHeap.ExtractMax();
Expand All @@ -32,7 +31,6 @@ public T Dequeue()
/// <summary>
/// Time complexity:O(1).
/// </summary>
/// <returns></returns>
public T Peek()
{
return maxHeap.PeekMax();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public T Dequeue()
/// <summary>
/// Time complexity:O(1).
/// </summary>
/// <returns></returns>
public T Peek()
{
return minHeap.PeekMin();
Expand Down
2 changes: 0 additions & 2 deletions Advanced.Algorithms/DataStructures/Queues/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public Queue(QueueType type = QueueType.Array)
/// <summary>
/// Time complexity:O(1).
/// </summary>
/// <param name="item"></param>
public void Enqueue(T item)
{
queue.Enqueue(item);
Expand All @@ -40,7 +39,6 @@ public void Enqueue(T item)
/// <summary>
/// Time complexity:O(1).
/// </summary>
/// <returns></returns>
public T Dequeue()
{
return queue.Dequeue();
Expand Down
Loading