table expand fast ...

Prev Next

Function Names

table expand fast, table expand fast ignore case

Description

This function works similarly to table expand(), with the only exception that the additional roes resulting from multiple lookups are appended at the bottom of the table rather than inserting them below the original row. For very large target tables, this approach saves significant becuase no rows will be shifted repeatedly. Consider sorting the table, e.g. using table sort rows() afterwards, if needed.

Function 'table expand fast'

Attention: Do not confuse with the functions table lookup fast() and table integrate fast() where the 'fast' in the function name refers to an optimized searching scheme suitable for pre-sorted tables.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

6 - 9 (For parameter description and return values: see table integrate() )

Examples


       table initialize( nute facts, // Nutritional facts, source: ndb.nal.usda.gov
       {  {  Food, Ingredient, Portion  },
          {  potato chips,  fat,            0.34  },
          {  potato chips,  carbohydrates,  0.50  },
          {  potato chips,  sodium,         0.08  },
          {  potato chips,  proteins,       0.07  },
          {  potato chips,  others,           ''  }, // Remaining weight subtracted from above (--> operation identifer 'mul')
          {  broccoli,      water,          0.90  },
          {  broccoli,      proteins,       0.03  },
          {  broccoli,      carbohydrates,  0.06  },
          {  broccoli,      others,           ''  }, // Remaining weight subtracted from above (--> operation identifer 'mul')
          {  spring water,  water,          1.00  } } );

       table initialize( target, { { Name, Favorite Food, Weight },
          { Rafael, Broccoli,    200 }, { Steve, Parmesan cheese, 100 }, { Stephanie, Parmesan cheese, 200 },
          { Jane,   Potato chips,100 }, { Nick, Potato chips, 50 },      { Fred,  Spring water,   1000 } } );


       echo("Target table before looking up with expanding contents:");
       table list ( target );

       count[] = table expand fast ignore case( target, Favorite Food, { Ingredient, Weight }, nute facts, Food,
                                 { Ingredient, Portion }, { overwrite, mul}, true, Counter );

       echo("Lookup table:");
       table list ( nute facts );

       // Note that food portions are multiplied with the weight of the food.

       echo("After expanding (listing ingredients and calculating their weights):");
       echo("Note: Nothing found for parmesan cheese.");
       echo("Target table after lookup (", count[], " items found):");
       table list ( target );

Output

Target table before looking up with expanding contents:
    0 : Name      | Favorite Food   | Weight
    1 : Rafael    | Broccoli        | 200   
    2 : Steve     | Parmesan cheese | 100   
    3 : Stephanie | Parmesan cheese | 200   
    4 : Jane      | Potato chips    | 100   
    5 : Nick      | Potato chips    | 50    
    6 : Fred      | Spring water    | 1000  

Lookup table:
    0 : Food         | Ingredient    | Portion | Counter
    1 : potato chips | fat           | 0.34    | 2      
    2 : potato chips | carbohydrates | 0.50    | 2      
    3 : potato chips | sodium        | 0.08    | 2      
    4 : potato chips | proteins      | 0.07    | 2      
    5 : potato chips | others        |         | 2      
    6 : broccoli     | water         | 0.90    | 1      
    7 : broccoli     | proteins      | 0.03    | 1      
    8 : broccoli     | carbohydrates | 0.06    | 1      
    9 : broccoli     | others        |         | 1      
   10 : spring water | water         | 1.00    | 1      

After expanding (listing ingredients and calculating their weights):
Note: Nothing found for parmesan cheese.
Target table after lookup (15 items found):
    0 : Name      | Favorite Food   | Weight | Ingredient   
    1 : Rafael    | Broccoli        | 180    | water        
    2 : Steve     | Parmesan cheese | 100    |              
    3 : Stephanie | Parmesan cheese | 200    |              
    4 : Jane      | Potato chips    | 34     | fat          
    5 : Nick      | Potato chips    | 17     | fat          
    6 : Fred      | Spring water    | 1000   | water        
    7 : Rafael    | Broccoli        | 6      | proteins     
    8 : Rafael    | Broccoli        | 12     | carbohydrates
    9 : Rafael    | Broccoli        | 2      | others       
   10 : Jane      | Potato chips    | 50     | carbohydrates
   11 : Jane      | Potato chips    | 8      | sodium       
   12 : Jane      | Potato chips    | 7      | proteins     
   13 : Jane      | Potato chips    | 1      | others       
   14 : Nick      | Potato chips    | 25     | carbohydrates
   15 : Nick      | Potato chips    | 4      | sodium       
   16 : Nick      | Potato chips    | 3.5    | proteins     
   17 : Nick      | Potato chips    | 0.5    | others       

Try it yourself: Open LIB_Function_table_expand_fast.b4p in B4P_Examples.zip. Decompress before use.

See also

table expand
table expand fast smart
table expand fast with rules
table expand fast with rules once