weight, weight profile
The function weight() returns the total number of base and member variables and also their sub-members. The 2nd function parameter
(option) allows to fine-tune the specification in order to obtain the desired results. It is possible to weigh member variables only. In this case,
the weighing begins at the level of the member variable and ignores the parental base and member variables.
The function weight profile provides more detailed weight information for every level in the variable tree. The base variable is
level 0, its array and structure members are at level 1, their sub-members at level 2, etc. The value returned is a set containing
the weight fore every level found.
Indirect parameter passing is disabled
1, 2
No. | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 code |
variable :string |
Variable name This variable including all its members and sub-members will be weighed. | ||||||||||||
Opt. 2 input |
string | Option The following options are supported to calculate the weight:
Note:All data of any type will be counted as 1, regardless if is is just a boolean or numeric value, a very long string or a sophisticated set. Default value: all |
Type | Description |
---|---|
numeral | Weight value Number of base and member variables as specified in the function parameters |
set | Weight profile If weight profile is called, the the weight values are provided for every level as numerals in a paramter set. The size of the set corresponds to the depth of the variable. |
dim( a[], 10, 0 ); // Level 1
a[0] = null();
dim( a[3], 5, 0 ); // Level 2
a[3,0] = null();
a[3,1] = null();
structure( a[3,2], { Ha, He, Hi, Ho }, { 1, 2, 3, 4 } ); // Level 3
see( a[] );
for all( { all, members, valid, valid members, leaves, valid leaves }, option[] )
echo( option[], ' -- weight: &tab32;', weight( a[], option[]), " Profile: ", weight profile( a[], option[]) );
// Note: '&tab32;' is a B4P specific HTML like entity to advance to any tab position between 1 and 300. Here position 32 is chosen.
a[] [Void] (void,full access)
Array [ 0] [Void] (void,full access)
Array [ 1] 0 "0" (numeral,full access)
Array [ 2] 0 "0" (numeral,full access)
Array [ 3] 0 "0" (numeral,full access)
Array [ 0] [Void] (void,full access)
Array [ 1] [Void] (void,full access)
Array [ 2] 0 "0" (numeral,full access)
Ha 1 "1" (numeral,full access)
He 2 "2" (numeral,full access)
Hi 3 "3" (numeral,full access)
Ho 4 "4" (numeral,full access)
Array [ 3] 0 "0" (numeral,full access)
Array [ 4] 0 "0" (numeral,full access)
Array [ 4] 0 "0" (numeral,full access)
Array [ 5] 0 "0" (numeral,full access)
Array [ 6] 0 "0" (numeral,full access)
Array [ 7] 0 "0" (numeral,full access)
Array [ 8] 0 "0" (numeral,full access)
Array [ 9] 0 "0" (numeral,full access)
all -- weight: 20 Profile: {1,10,5,4}
members -- weight: 19 Profile: {0,10,5,4}
valid -- weight: 16 Profile: {0,9,3,4}
valid members -- weight: 16 Profile: {0,9,3,4}
leaves -- weight: 17 Profile: {0,9,4,4}
valid leaves -- weight: 14 Profile: {0,8,2,4}