Halstead difficulty metrics implementation issues

I am currently training with a simple program to understand the equations associated with deriving various metrics from Halstead software science. I believe that I am doing it right, but it seems to me that I have not registered all the operands and operators to start with mathematics.

The program I use:

/*01*/ // counts how many items in sArray[] are also in tArray[]
/*02*/ int matched(int sArray[], int tArray[], int sMax, int tMax)
/*03*/ {
/*04*/    int count, i, first, middle, last;
/*05*/ 
/*06*/    for (i = 0; i < sMax; ++i)
/*07*/    {
/*08*/        last = tMax - 1;
/*09*/        for (int first = 0; first <= last;)
/*10*/        {
/*11*/            middle = (first + last) / 2;
/*12*/            if (tArray[middle] == sArray[i])
/*13*/            {
/*14*/                 count++;
/*15*/                 break;
/*16*/            } 
/*17*/            if (tArray[middle] < sArray[i]) 
/*18*/            {
/*19*/                 first = middle + 1;
/*20*/            }
/*21*/            else
/*22*/            {
/*23*/                 last =  middle - 1;
/*24*/            }
/*25*/         }
/*26*/    }
/*27*/    return count;
/*28*/ }

And I went out with

  • n1 = number of different operators = 10
  • n2 = number of different operands = 9
  • N1 = total number of operators = 24
  • N2 = total number of operands = 34

These notes show various operators and operands found:


= ( 6, 8, 9, 11, 19, 23) = 6 < , ( 6, 17) = 2
++ ( 6, 14) = 2
- ( 8, 23) = 2
<= ( 9) = 1
+ ( 11, 19) = 2
/ ( 11) = 1
== ( 12) = 1
[] ( 2 * 2, 12 * 2, 17 * 2 = 6
break ( 15) = 1


count ( 4, 14) = 2
( 4, 6 * 3, 12, 17) = 6 ( 4, 9) * 2, 11, 19) = 5
( 4, 11, 12, 17, 19, 23) = 6
( 4, 8, 9, 11, 23) = 5
sArray ( 2, 12, 17) = 3
tArray ( 2, 12, 17) = 3
sMax ( 2, 6) = 2
tMax ( 2, 8) = 2

- , ? :

  • -
+4
2

" ", " " .. Halstead , :

Difficulty = (Unique Operators / 2) * (Operands / Unique Operands);

, , , .

: {} , . (), , . (, , )

matched , ( ).

: . , [], [] 12 17, . - , - operator[] - . postfix ++, .

: for, if, else, break, return. , .

: . , - . Difficulty, , , , , .

, , .

Operators 
= Assignment (line 6, 8, 9, 11, 19, 23) = 6 
< Less Than (line 6, 17) = 2 
++ Prefix Increment (line 6) = 1
++ Postfix Increment (line 14) = 1 
- Subtract (line 8, 23) = 2 
<= Less Than or Equal to (line 9) = 1 
+ Addition (line 11, 19) = 2 
/ Division (line 11) = 1 
== Equal to (line 12) = 1
[] declaration (line 2) = 2 
[] index (line 12, 17) = 4
for (line 6, 9) = 2
if (line 12, 17) = 2
else (line 21) = 1
break (line 15) = 1
return (line 27) = 1
int declaration = 7

Operands 
count (line 4, 14) = 2 
i (line 4, 6*3, 12, 17) = 6 
first (line 4, 9*2, 11, 19) = 5 
middle (line 4, 11, 12, 17, 19, 23) = 6 
last (line 4, 8, 9, 11, 23) = 5 
sArray (line 2, 12, 17) = 3 
tArray (line 2, 12, 17) = 3 
sMax (line 2, 6) = 2 
tMax (line 2, 8) = 2

Metrics
n1 = 17
n2 = 9
N1 = 37
N2 = 34
Difficulty = (n1 * N2) / (2 * n2) = 32.1

Wiki Virtual Machinery.

, .

: 2, , ++: http://www.verifysoft.com/en_halstead_metrics.html.

+2

-, 0, , .

operators 
matched -1
() -6
[] -6
{} -6
int -7
for -2
if -2
else -1
return -1
= -6 
< -2
<= -1
++ -2
- -2
+ -2
/ -1
== -1
break -1

operands
2 -line no. 11 -1
1 (8,19,23) -3
0 -1
count -3
i -6
first -5
middle -6
last -5
sArray -3
tArray -3
sMax -2
tMax -2

N1=50
N2=40
n1=18
n2=12

, , - . → http://profs.etsmtl.ca/aabran/English/Accueil/ChapersBook/Abran%20-%20Chapter%20005.pdf

, .

, , ,

, , .

, .

0

All Articles