T
tak
hi,
i am looking for a data structure for fast retrievals... and here is my
scenario.
this table is about foreigncy exchange. i will have a buy currency,
sellcurrency, levels, and rate.
A transaction involves from a BUY currency to Sell currency, and it can
have multiple levels, meaning... if the sell amount is 1000, the rate
is 1.1, but if the sell amount is 2000, the rate is 1.2..etc...
Say there is a fixed amount of currencies that I need to maintain (say
10 type only) And I need to store all these rates in a structure, for
fast retrieval..
More concrete example.
Sell : USD Buy: EUR Level: 1 - 1000 rate: 1.1
Sell : USD Buy: EUR Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: EUR Level: 5000 - 99999999 rate: 1.3
Sell : USD Buy: CAD Level: 1 - 1000 rate: 1.1
Sell : USD Buy: CAD Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: CAD Level: 5000 - 99999999 rate: 1.3
Sell : USD Buy: GBP Level: 1 - 1000 rate: 1.1
Sell : USD Buy: GBP Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: GBP Level: 5000 - 99999999 rate: 1.3
------ So, Sell for USD type is finished here.
Sell : EUR Buy: USD Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: USD Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: USD Level: 5000 - 99999999 rate: 1.3
Sell : EUR Buy: CAD Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: CAD Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: CAD Level: 5000 - 99999999 rate: 1.3
Sell : EUR Buy: GBP Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: GBP Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: GBP Level: 5000 - 99999999 rate: 1.3
------ Sell for EUR is finished here.
so on with GBP, and CAD.
my requirements:
Say, someone tell me, what are all the rates for all the levels and
BuyType from EUR as sell?
Then that means I have to send back all the EUR as sell type.
Or, if someone say, what are all the rates for all the buytype for USD
from EUR as sell?
Then that means i have to send back all the EUR as sell, and USD for
Buy.
Or, if someone say, what are all the rates for all the buytype as GBP?
Then, i will have to send back all the buytype as GBP (including all
levels)
Or someone can just ask for a specific level as well for any buy type
of sell type, or both.
I was thinking about hash of hash... but if i have the Sell type as key
of the outer hash... then the inner hash will need to have a buytype as
the key... but then, i will have multiple levels...if i put the
multiple levels in an array of an object, and this object as the value
of this inner hash, that should be fine... but i am worry about the
speed.
Ideas?
thanks,
T
i am looking for a data structure for fast retrievals... and here is my
scenario.
this table is about foreigncy exchange. i will have a buy currency,
sellcurrency, levels, and rate.
A transaction involves from a BUY currency to Sell currency, and it can
have multiple levels, meaning... if the sell amount is 1000, the rate
is 1.1, but if the sell amount is 2000, the rate is 1.2..etc...
Say there is a fixed amount of currencies that I need to maintain (say
10 type only) And I need to store all these rates in a structure, for
fast retrieval..
More concrete example.
Sell : USD Buy: EUR Level: 1 - 1000 rate: 1.1
Sell : USD Buy: EUR Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: EUR Level: 5000 - 99999999 rate: 1.3
Sell : USD Buy: CAD Level: 1 - 1000 rate: 1.1
Sell : USD Buy: CAD Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: CAD Level: 5000 - 99999999 rate: 1.3
Sell : USD Buy: GBP Level: 1 - 1000 rate: 1.1
Sell : USD Buy: GBP Level: 1000 - 5000 rate: 1.2
Sell : USD Buy: GBP Level: 5000 - 99999999 rate: 1.3
------ So, Sell for USD type is finished here.
Sell : EUR Buy: USD Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: USD Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: USD Level: 5000 - 99999999 rate: 1.3
Sell : EUR Buy: CAD Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: CAD Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: CAD Level: 5000 - 99999999 rate: 1.3
Sell : EUR Buy: GBP Level: 1 - 1000 rate: 1.1
Sell : EUR Buy: GBP Level: 1000 - 5000 rate: 1.2
Sell : EUR Buy: GBP Level: 5000 - 99999999 rate: 1.3
------ Sell for EUR is finished here.
so on with GBP, and CAD.
my requirements:
Say, someone tell me, what are all the rates for all the levels and
BuyType from EUR as sell?
Then that means I have to send back all the EUR as sell type.
Or, if someone say, what are all the rates for all the buytype for USD
from EUR as sell?
Then that means i have to send back all the EUR as sell, and USD for
Buy.
Or, if someone say, what are all the rates for all the buytype as GBP?
Then, i will have to send back all the buytype as GBP (including all
levels)
Or someone can just ask for a specific level as well for any buy type
of sell type, or both.
I was thinking about hash of hash... but if i have the Sell type as key
of the outer hash... then the inner hash will need to have a buytype as
the key... but then, i will have multiple levels...if i put the
multiple levels in an array of an object, and this object as the value
of this inner hash, that should be fine... but i am worry about the
speed.
Ideas?
thanks,
T