Tariff Table - Tuple Key Pattern Matching

Rudolph van Graan rvg@REDACTED
Mon Jan 5 07:52:41 CET 2004

Hi Daniel,

Why don't you use mnemosyne for this? I haven't compiled this fragment, 
so you might find some bugs here. The general idea is to use match 
clauses for the tests. In this case, if a clause doesn't match, the 
record is not returned. You can modify this to have more intelligent 
tests that not only tests for a first char match.

find_tariffs(TableName,Tariff) ->
   Handle = query
     [ T || T <- table(tarifftable),
            {TariffTable,TariffValue} = T. tarifftablekey, %Extract the 
two values from the key
	       [FirstChar|Rest] = TariffValue,                   %Extract the 
first char from the Tariff value
	       [FirstChar|RestOfTariff] = Tariff ]               %Test the 
input tariff against the input tariff
   QuerySetup = mnemosyne:setup_query(Handle),
   R =
       fun() ->
           Cursor = mnemosyne:init_query(QuerySetup),



On Jan 3, 2004, at 2:20 AM, Inswitch Solutions - Erlang Evaluation 

> Hi,
> I hope someone can give as some help about this issue. We are trying 
> to optimizemnesiaaccess time, to phone tariff tables.
> This tariff tables, have about 4000 entries each.
>  The index is a tuplekey as follows:
> {“Tariff_Table_Name”,”Prefix”}
> where
> Tariff_Table_Name, is the name of the Tariff plan that applies to the 
> subscriber
> And
> Prefix, is a string, the first digits of the called number.
> So our queries are (Tariff Table Name=”TARIFF”):
> MatchHead= #tarifftable{tarifftablekey='$1', _='_'},
>  Guard = [{'==',{element,1,'$1'}, "TARIFF"}],
>  Result = '$1',
>  Select =fun() ->
>               mnesia:select(tarifftable,[{MatchHead, Guard, [Result]}])
>            end,
>  {atomic,Res} =mnesia:transaction(Select),
>  Res.
> So, as a result, it brings 4000tuples, of the form 
> “{“Tariff_Table_Name”,”Prefix”}
> Later the application searches for the “prefix” that bettermartchesthe 
> called number (the prefix is a substring of the called number). My 
> question is, instead of bringing all 4000tuples, can I bring just the 
> most similar “Prefix”, like the one which have anspecific 
> firstcaracter? So instead of bringing 4000tuples, I may bring just the 
> most similar ones (the prefixes which are more similar to the 
> destination number?)
> Best Regards,
> daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4317 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040105/cb7dcfcf/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2112 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040105/cb7dcfcf/attachment-0001.bin>

More information about the erlang-questions mailing list