Skip to content
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

BitList structure #143

Closed
wants to merge 17 commits into from
Closed

BitList structure #143

wants to merge 17 commits into from

Conversation

@LorenzoLotti
Copy link
Contributor

@LorenzoLotti LorenzoLotti commented May 20, 2020

BitList data structure.

  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have added comments to hard-to-understand areas of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the comments
  • I have made corresponding changes to the README.md
@codecov
Copy link

@codecov codecov bot commented May 20, 2020

Codecov Report

Merging #143 into master will decrease coverage by 3.55%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
- Coverage   88.25%   84.69%   -3.56%     
==========================================
  Files          58       50       -8     
  Lines        2461     1562     -899     
==========================================
- Hits         2172     1323     -849     
+ Misses        289      239      -50     
Impacted Files Coverage Δ
Algorithms/Search/FastSearcher.cs 95.65% <0.00%> (ø)
DataStructures/BitArray.cs
...tructures/DoublyLinkedList/DoublyLinkedListNode.cs
DataStructures/ArrayBasedStack/ArrayBasedStack.cs
DataStructures/ListBasedStack/ListBasedStack.cs
...ataStructures/DoublyLinkedList/DoublyLinkedList.cs
DataStructures/MinMaxHeap.cs
...ataStructures/SinglyLinkedList/SinglyLinkedList.cs
...tructures/SinglyLinkedList/SinglyLinkedListNode.cs

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 470759b...4366b0e. Read the comment docs.

@siriak
Copy link
Member

@siriak siriak commented May 22, 2020

Thank you for the bit list, I'll take a look at it when I have more time, or maybe someone else will review it in the meantime!

@LorenzoLotti LorenzoLotti changed the title Create BitList.cs BitList structure May 30, 2020
LorenzoLotti added 16 commits May 31, 2020
Equality operator stack overflow fixed
BitList.cs tests
Changes (100% safe code):
- 1 new ctor: BitList.BitList(ValueType unmanagedNonPrimitiveBits)
- 2 new methods:
    - T[] ToUnmanagedNonPrimitiveValueArray<T>() where T : unmanaged
    - void CopyTo<T>(T[] unmanagedNonPrimitiveValueArray, int arrayIndex) where T : unmanaged

New ctor:
The new ctor create a BitList instance by converting the ValueType param (must be unmanaged and non primitive) in a safe buffer.

New method 1:
Convert the BitList content to an array of a specified unmanaged and non primitive value type (no pointers).

New method 2:
Copy the BitList content to an array of a specified unmanaged and non primitive value type (no pointers);
Copy link
Member

@siriak siriak commented Jun 23, 2020 — with Codacy Production

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 19
           

Complexity increasing per file
==============================
- DataStructures.Tests/BitListTest.cs  3
- DataStructures/BitList.cs  16
         

See the complete overview on Codacy

/// <summary>
/// Ctor (<paramref name="unmanagedNonPrimitiveBits"/> is an unmanaged value type object).
/// </summary>
public BitList(ValueType unmanagedNonPrimitiveBits)
var text = string.Empty;
foreach (var bit in ToBooleanArray())
{
text += bit ? "1" : "0";

This comment has been minimized.

@siriak

siriak Jun 23, 2020
Member

Codacy found an issue: Use a StringBuilder instead.

/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T[] ToUnmanagedNonPrimitiveValueArray<T>() where T : unmanaged
var result = new List<T>(); //A list of unmanaged non primitive value type objects.
for (var i = 0; i < bytes.Count; i += size)
{
if (typeof(T).IsEnum)
}
else
{
throw new IndexOutOfRangeException();
break;

default:
case "Int32":

This comment has been minimized.

get => Get(index, count);
set
{
if (count >= value.Count)

This comment has been minimized.

@siriak

siriak Jun 23, 2020
Member

Codacy found an issue: Use the '?:' operator here.

var bits = new BitList(1F);
var array = new float[1];
bits.CopyTo(array, 0);
Assert.IsTrue(array.Length == 1 && array[0] == 1);
/// </summary>
public BitList Get(int index, int count)
{
if (!IsEmpty && index < bits.Length && index >= 0 && index + count <= bits.Length - index && count > 0)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T[] ToUnmanagedNonPrimitiveValueArray<T>() where T : unmanaged
return ToBooleanArray().ToList().GetEnumerator();
}

private class Unmanaged<T> where T : unmanaged { }

This comment has been minimized.

/// </summary>
public void Set(int index, BitList value)
{
if (!IsEmpty && index < bits.Length && index >= 0 && index + value.Count <= bits.Length - index && value.Count > 0)
break;

default:
case "UInt32":

This comment has been minimized.

@siriak
Copy link
Member

@siriak siriak commented Jun 29, 2020

Thanks for the BitList! I see that it's a wrapper over BitArray, why would anyone want one? This repository focuses on implementing data structures, but this implementation uses BitArray under the hood. Also, there are methods that are not essential for Bit(Array|List) and I would suggest removing them (file IO, copying, constructor overloads).

@LorenzoLotti
Copy link
Contributor Author

@LorenzoLotti LorenzoLotti commented Jun 29, 2020

@LorenzoLotti
Copy link
Contributor Author

@LorenzoLotti LorenzoLotti commented Jun 29, 2020

@LorenzoLotti
Copy link
Contributor Author

@LorenzoLotti LorenzoLotti commented Jun 29, 2020

@siriak
Copy link
Member

@siriak siriak commented Jun 30, 2020

Based on the information you provided, I suggest:

  • Base implementation on an array or something other than BitArray for educational purposes
  • Remove methods related to file IO because they violate SRP
  • Reduce the number of constructors because this class is too cluttered
  • Fix Codacy comments and build (I cannot merge before all checks pass)
@LorenzoLotti
Copy link
Contributor Author

@LorenzoLotti LorenzoLotti commented Jul 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.