Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Aug 9, 2020
2 parents e6e1c67 + 476f439 commit 5b85975
Show file tree
Hide file tree
Showing 123 changed files with 313 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Task Document -depends Build {
git config --global credential.helper store
Add-Content "$HOME\.git-credentials" "https://$($env:github_access_token):[email protected]`n"
git config --global user.email $env:github_email
git config --global user.name "buildbot121"
git config --global user.name "buildbot171"
git add . -A
git commit -m "API documentation update by build server"
git push origin master
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Note:

Please don't take effort to create pull requests for new algorithms/data structures. This is just a curiosity driven personal hobby and [was originally not intented to be a library](https://github.com/justcoding121/Advanced-Algorithms/issues/2). Feel free fork and modify to fit your need if that's what you are looking for. You can however open issues/fix bugs with pull requests here, I would be happy to take a look when I get time.
Please don't take effort to create pull requests for new algorithms/data structures. This is just a curiosity-driven personal hobby and [was originally not intended to be a library](https://github.com/justcoding121/Advanced-Algorithms/issues/2). Feel free fork and modify to fit your need if that's what you are looking for. You can, however, open issues/fix bugs with pull requests here, I would be happy to take a look when I get time

## Advanced Algorithms

Expand Down Expand Up @@ -77,7 +77,7 @@ Supports
- [X] Fibonacci heap ([implementation](https://github.com/justcoding121/Advanced-Algorithms/blob/master/src/Advanced.Algorithms/DataStructures/Heap/FibonacciHeap.cs) | [tests](https://github.com/justcoding121/Advanced-Algorithms/blob/master/tests/Advanced.Algorithms.Tests/DataStructures/Heap/FibonacciHeap_Tests.cs))
- [X] Pairing heap ([implementation](https://github.com/justcoding121/Advanced-Algorithms/blob/master/src/Advanced.Algorithms/DataStructures/Heap/PairingHeap.cs) | [tests](https://github.com/justcoding121/Advanced-Algorithms/blob/master/tests/Advanced.Algorithms.Tests/DataStructures/Heap/PairingHeap_Tests.cs))

Note: It is observed that among the implementations here in practice, with the exclusion of UpdateKey (decrement/increment) operation regular Binary Heap & d-ary Heap outperforms other in theory superiors. Likely because it don't have pointer juggling overhead and hey arrays are faster!
Note: It is observed that among the implementations here, in practice, with the exclusion of UpdateKey (decrement/increment) operation, regular Binary Heap & d-ary Heap outperforms other in theory superiors. Likely because it doesn't have pointer juggling overhead and hey arrays are faster!

### Tree

Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test: on
skip_tags: true

skip_commits:
author: buildbot121
author: buildbot171
files:
- docs/*
- README.md
Expand All @@ -58,11 +58,11 @@ artifacts:

environment:
github_access_token:
secure: BGdKiI7FwHGkFt+/OmgZDkE1hzLqLrTxcc9c+joVqGyO4LvesHb1sR6hzisVwVPm
secure: mZLeq0GTB9kb5b6+HnVpJB6hhiYMJIQ2+Zf/DwZ/LEIyxJaYB1nx36aGHXE9q1cN
github_email:
secure: wvYod3JLufbIBkavRXlCP724wJkhqR2RRuLLaPnqfps=
secure: iBJZGqxyiHVNeYI0uIW+MdGd3I3pg8brJtETNRkKe/A=
nuget_access_token:
secure: ZbRmjOcp+TDllRV1wxqLZjdRV7hld388rXlWVJuGGiQleomP9Ku+Nsy3a75E7/9k
secure: 65rklofkoUWJzPPja621kXlxrruHemmbREnIX7QgXK0cydW412yYMZJQsN42Js27
deploy:
- provider: GitHub
auth_token: $(github_access_token)
Expand Down
2 changes: 1 addition & 1 deletion src/Advanced.Algorithms/Binary/BaseConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text;

namespace Advanced.Algorithms.Binary
{
{
/// <summary>
/// Base conversion implementation.
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Advanced.Algorithms/Compression/HuffmanCoding.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Advanced.Algorithms.DataStructures;
using System;
using System.Collections.Generic;
using Advanced.Algorithms.DataStructures;

namespace Advanced.Algorithms.Compression
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public Dictionary<T, byte[]> Compress(T[] input)
/// </summary>
private void dfs(FrequencyWrap currentNode, List<byte> pathStack, Dictionary<T, byte[]> result)
{
if(currentNode.IsLeaf)
if (currentNode.IsLeaf)
{
result.Add(currentNode.Item, pathStack.ToArray());
return;
Expand Down Expand Up @@ -114,7 +114,7 @@ public FrequencyWrap(T item, int frequency)

public int CompareTo(object obj)
{
return Frequency.CompareTo(((FrequencyWrap) obj).Frequency);
return Frequency.CompareTo(((FrequencyWrap)obj).Frequency);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Advanced.Algorithms.DataStructures.Foundation
/// </summary>
/// <typeparam name="K">The key datatype.</typeparam>
/// <typeparam name="V">The value datatype.</typeparam>
public class Dictionary<K, V> : IEnumerable<KeyValuePair<K, V>>
public class Dictionary<K, V> : IEnumerable<KeyValuePair<K, V>>
{
private readonly IDictionary<K, V> dictionary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Advanced.Algorithms.DataStructures.Foundation
{
internal class OpenAddressDictionary<TK, TV> : IDictionary<TK, TV>
internal class OpenAddressDictionary<TK, TV> : IDictionary<TK, TV>
{
private DictionaryKeyValuePair<TK, TV>[] hashArray;
private int bucketSize => hashArray.Length;
Expand Down Expand Up @@ -368,7 +368,7 @@ internal DictionaryKeyValuePair(K key, V value)
}
}

internal class OpenAddressDictionaryEnumerator<TK, TV> : IEnumerator<KeyValuePair<TK, TV>>
internal class OpenAddressDictionaryEnumerator<TK, TV> : IEnumerator<KeyValuePair<TK, TV>>
{
internal DictionaryKeyValuePair<TK, TV>[] HashArray;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Advanced.Algorithms.DataStructures.Foundation
{
internal class SeparateChainingDictionary<K, V> : IDictionary<K, V>
internal class SeparateChainingDictionary<K, V> : IDictionary<K, V>
{
private const double tolerance = 0.1;

Expand All @@ -15,7 +15,7 @@ internal class SeparateChainingDictionary<K, V> : IDictionary<K, V>

public int Count { get; private set; }


public SeparateChainingDictionary(int initialBucketSize = 3)
{
this.initialBucketSize = initialBucketSize;
Expand Down Expand Up @@ -301,7 +301,7 @@ public IEnumerator<KeyValuePair<K, V>> GetEnumerator()

}

internal class SeparateChainingDictionaryEnumerator<TK, TV> : IEnumerator<KeyValuePair<TK, TV>>
internal class SeparateChainingDictionaryEnumerator<TK, TV> : IEnumerator<KeyValuePair<TK, TV>>
{
internal DoublyLinkedList<KeyValuePair<TK, TV>>[] HashList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WeightedGraph<T, TW> : IGraph<T>, IEnumerable<T> where TW : ICompar
private Dictionary<T, WeightedGraphVertex<T, TW>> vertexObjects;

public int VerticesCount => usedSize;
public bool IsWeightedGraph => true;
public bool IsWeightedGraph => true;

public WeightedGraph()
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public bool HasEdge(T source, T dest)
return false;
}

public IEnumerable<KeyValuePair<T,TW>> Edges(T vertex)
public IEnumerable<KeyValuePair<T, TW>> Edges(T vertex)
{
if (!vertexIndices.ContainsKey(vertex))
{
Expand All @@ -214,7 +214,7 @@ public IEnumerable<KeyValuePair<T,TW>> Edges(T vertex)

for (int i = 0; i < maxSize; i++)
{
if (!matrix[i,index].Equals(default(TW)))
if (!matrix[i, index].Equals(default(TW)))
{
yield return new KeyValuePair<T, TW>(reverseVertexIndices[i], matrix[i, index]);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ private void halfMatrixSize()
{
for (int j = i; j < maxSize; j++)
{
if (!matrix[i, j].Equals(default(TW)) && !matrix[j,i].Equals(default(TW))
if (!matrix[i, j].Equals(default(TW)) && !matrix[j, i].Equals(default(TW))
&& reverseVertexIndices.ContainsKey(i)
&& reverseVertexIndices.ContainsKey(j))
{
Expand All @@ -320,7 +320,7 @@ private void halfMatrixSize()
reverseVertexIndices = newReverseIndices;
}

public IEnumerable<IGraphVertex<T>> VerticesAsEnumberable => vertexObjects.Select(x=>x.Value);
public IEnumerable<IGraphVertex<T>> VerticesAsEnumberable => vertexObjects.Select(x => x.Value);

IEnumerator IEnumerable.GetEnumerator()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Advanced.Algorithms/DataStructures/Graph/IDiGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Advanced.Algorithms.DataStructures.Graph
/// Directed graph.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IDiGraph<T>
public interface IDiGraph<T>
{
bool IsWeightedGraph { get; }

Expand All @@ -19,7 +19,7 @@ public interface IDiGraph<T>

bool HasEdge(T source, T destination);

IDiGraph<T> Clone();
IDiGraph<T> Clone();
}

public interface IDiGraphVertex<T>
Expand Down
3 changes: 0 additions & 3 deletions src/Advanced.Algorithms/DataStructures/Graph/IGraph.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Advanced.Algorithms.DataStructures.Graph
{
Expand Down
2 changes: 1 addition & 1 deletion src/Advanced.Algorithms/DataStructures/HashSet/HashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Advanced.Algorithms.DataStructures.Foundation
/// A hash table implementation.
/// </summary>
/// <typeparam name="T">The value datatype.</typeparam>
public class HashSet<T> : IEnumerable<T>
public class HashSet<T> : IEnumerable<T>
{
private readonly IHashSet<T> hashSet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Advanced.Algorithms.DataStructures.Foundation
{
internal class OpenAddressHashSet<T> : IHashSet<T>
internal class OpenAddressHashSet<T> : IHashSet<T>
{
private HashSetNode<T>[] hashArray;
private int bucketSize => hashArray.Length;
private readonly int initialBucketSize;

public int Count { get; private set; }

internal OpenAddressHashSet(int initialBucketSize = 2)
{
this.initialBucketSize = initialBucketSize;
Expand Down Expand Up @@ -281,7 +281,7 @@ internal HashSetNode(T value)
}
}

internal class OpenAddressHashSetEnumerator<V> : IEnumerator<V>
internal class OpenAddressHashSetEnumerator<V> : IEnumerator<V>
{
internal HashSetNode<V>[] hashArray;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public int IndexOf(T key)
/// </summary>
public int Remove(T key)
{
return binarySearchTree.Delete(key);
return binarySearchTree.Delete(key);
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public int Remove(T key)
/// </summary>
public T RemoveAt(int index)
{
return binarySearchTree.RemoveAt(index);
return binarySearchTree.RemoveAt(index);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Advanced.Algorithms.DataStructures.Foundation
{
internal class SeparateChainingHashSet<T> : IHashSet<T>
internal class SeparateChainingHashSet<T> : IHashSet<T>
{
private const double tolerance = 0.1;
private DoublyLinkedList<HashSetNode<T>>[] hashArray;
Expand Down Expand Up @@ -267,7 +267,7 @@ public IEnumerator<T> GetEnumerator()

}

internal class SeparateChainingHashSetEnumerator<T> : IEnumerator<T>
internal class SeparateChainingHashSetEnumerator<T> : IEnumerator<T>
{
internal DoublyLinkedList<HashSetNode<T>>[] hashList;

Expand Down
2 changes: 1 addition & 1 deletion src/Advanced.Algorithms/DataStructures/Heap/BHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void bulkInitRecursive(int i, T[] initial)
var left = 2 * i + 1;
var right = 2 * i + 2;

var minMax = left < initial.Length && right < initial.Length ?
var minMax = left < initial.Length && right < initial.Length ?
comparer.Compare(initial[left], initial[right]) < 0 ? left : right
: left < initial.Length ? left
: right < initial.Length ? right : -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Insert(T newItem)
}

addMapping(newItem, newNode);

Count++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal FibonacciHeapNode(T value)

public int CompareTo(object obj)
{
return Value.CompareTo(((FibonacciHeapNode<T>) obj).Value);
return Value.CompareTo(((FibonacciHeapNode<T>)obj).Value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal PairingHeapNode(T value)

public int CompareTo(object obj)
{
return Value.CompareTo(((PairingHeapNode<T>) obj).Value);
return Value.CompareTo(((PairingHeapNode<T>)obj).Value);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Advanced.Algorithms/DataStructures/Heap/d-aryHeap.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Advanced.Algorithms.DataStructures
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public DaryHeap(int k, SortDirection sortDirection = SortDirection.Ascending, IE

Count = initArray.Length;
bulkInit(initArray);

}
else
{
Expand Down Expand Up @@ -152,7 +152,7 @@ public T Extract()
//init to left-most child
var minMaxChildIndex = findMinMaxChildIndex(currentParent, heapArray);

if (minMaxChildIndex!=-1 &&
if (minMaxChildIndex != -1 &&
comparer.Compare(heapArray[currentParent], heapArray[minMaxChildIndex]) > 0)
{
var tmp = heapArray[minMaxChildIndex];
Expand Down Expand Up @@ -245,7 +245,7 @@ private void doubleArray()
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();

}

public IEnumerator<T> GetEnumerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Advanced.Algorithms.DataStructures
/// <summary>
/// A doubly linked list implementation.
/// </summary>
public class DoublyLinkedList<T> :IEnumerable<T>
public class DoublyLinkedList<T> : IEnumerable<T>
{
public DoublyLinkedListNode<T> Head;
public DoublyLinkedListNode<T> Tail;
Expand Down Expand Up @@ -38,7 +38,7 @@ public DoublyLinkedListNode<T> InsertFirst(T data)
return newNode;
}

internal void InsertFirst(DoublyLinkedListNode<T> newNode)
internal void InsertFirst(DoublyLinkedListNode<T> newNode)
{
if (Head != null)
{
Expand Down Expand Up @@ -337,7 +337,7 @@ internal void Union(DoublyLinkedList<T> newList)
newList.Tail.Next = Head;

Head = newList.Head;


}

Expand Down Expand Up @@ -387,7 +387,7 @@ public DoublyLinkedListNode(T data)
}
}

internal class DoublyLinkedListEnumerator<T> : IEnumerator<T>
internal class DoublyLinkedListEnumerator<T> : IEnumerator<T>
{
internal DoublyLinkedListNode<T> headNode;
internal DoublyLinkedListNode<T> currentNode;
Expand Down
Loading

0 comments on commit 5b85975

Please sign in to comment.