HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Lightweight implementation of the in-close algorithm from C++ to C# translation

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
closethelightweightalgorithmimplementationfromtranslation

Problem

The following C++ code is a lightweight implementation of in-close algorithm. Full details of the project can be found here.

I was trying to translate the C++ code to C# but it's very difficult to manage. That new version simply doesn't work due to pointer implementation. In fact, I need to keep using pointers because performance is very important to me.

The actual code I need to use in C++ version:

```
#include //for file IO
#include //for cin >> and cout //for _kbhit
#include //for strings
#include
#include
#include
using namespace std;

//MAX VALUES:
#define MAX_CONS 50000000 //max number of concepts
#define MAX_COLS 5000 //max number of attributes
#define MAX_ROWS 1000000 //max number of objects
#define MAX_FOR_B 50000000 //memory for storing intents
#define MAX_FOR_A 1000000000 //memory for storing extents
//Change these in the as required and available RAM allows. Current values are for standard 64 bit Windows PC with 8GB RAM

__declspec(align(32)) unsigned __int64 **contextTemp; //temporary context matrix for input of cxt file and physical sorting of columns
__declspec(align(32)) unsigned __int64 **context; //the context matrix used for concept mining.

//the bit-wise columns in 'contextTemp' are transposed into bit-wise rows in 'context' for more efficient use of cache memory
int mArray; //size of bit-wise columns in temp context
int nArray; //size of bit-wise rows in context

int colOriginal[MAX_COLS]; //maps sorted columns to original order
int colSup[MAX_COLS]; //column support (for sorting and skipping empty columns)
int rowOriginal[MAX_ROWS]; //maps ham-sorted rows to original order

int n; //no of attributes {0,1,...,n-1}
int m; //no of objects {0,1,...,m-1}

/** linked list form of B[MAX_CONS][n] /
short int* B;

Solution

System.IO.StreamReader file = new System.IO.StreamReader(@"C:\FCA\mushroom.txt");
for (i = 0; i < m;i++ )
{
    // ...
}
file.Close();


Using using instead:

using (System.IO.StreamReader file = new System.IO.StreamReader(@"C:\FCA\mushroom.txt"))
{
    for (i = 0; i < m;i++ )
    {
        // ...
    }
}


This will ensure that file is disposed correctly.

return (true);


Those parenthesis are useless and confusing. Remove them.

if (size == 0)
{
    // ...
}
else
{
    if (size < sizeAc)
    {
        // ...
    }
    else
    {
        // ...
    }
}


This can become:

if (size == 0)
{
    // ...
}
else if (size < sizeAc)
{
    // ...
}
else
{
    // ...
}


int n;
int m;
int* B;


Those names don't tell me what the variable does or is used for. Using a longer, more descriptive name won't affect performance, and will make debugging and maintaining the code easier.

Code Snippets

System.IO.StreamReader file = new System.IO.StreamReader(@"C:\FCA\mushroom.txt");
for (i = 0; i < m;i++ )
{
    // ...
}
file.Close();
using (System.IO.StreamReader file = new System.IO.StreamReader(@"C:\FCA\mushroom.txt"))
{
    for (i = 0; i < m;i++ )
    {
        // ...
    }
}
return (true);
if (size == 0)
{
    // ...
}
else
{
    if (size < sizeAc)
    {
        // ...
    }
    else
    {
        // ...
    }
}
if (size == 0)
{
    // ...
}
else if (size < sizeAc)
{
    // ...
}
else
{
    // ...
}

Context

StackExchange Code Review Q#95802, answer score: 3

Revisions (0)

No revisions yet.