Re: What file structure for this type of data ?

From: vldm10 <vldm10_at_yahoo.com>
Date: 22 Mar 2007 13:46:22 -0700
Message-ID: <1174596382.573847.201030_at_e1g2000hsg.googlegroups.com>


On Mar 21, 10:19 am, "cnlai" <c..._at_pc.jaring.my> wrote:
> Assume that I have the following data:
>
> Product, Category (assume all numerals)
>
> I need to perform the following queries at various times:
> 1. For a given product, what categories does it belong to (more than 1
> category possible) ?
> 2. For a given category, what products are available ?
>
> Questions
> 1. Without using a database, what file structure is suitable ? (If a B+ tree
> is used, 2 files are needed: one to collect all products belonging to a
> category, one to collect all categories for a product.)
>
> 2. In a database, what file structure is used for processing the above
> queries ?

You can solve your problem on the following way: Let F1 be file which represents the products and has key kproduct. Let F2 be file which represents the categories and has key kcategory. Now you will create new file F3 with the two fields: kproduct and kcategory.
You will also create the two keys for F3: K = (kproduct, kcategory)
(-K) = (kcategory, kproduct)
(Here keys are denoted as K and -K because I want to emphasize that they are inverse, however you can name the keys as you like) If you want to get all categories for product_n you will usefirst key as
Read K (product_n, 0)...
If you want to get all products for category_m you will use second key as
Read -K (category_m, 0)...
If you don't have software which supports random Read with the pair of values, then you can build small procedures which will support this. For previous - you can build "big picture" for example: how world is built.
For example you can use entity/relationship model and think that world is discrete, i.e. that there are some objects in the world which we interpret as the entities. Then we can think that some objects "know for each other" what we interpret as relationship. So you need at least two entities for relationship - it means it will be appropriate to work with two files, not with one.
This problem is matter of a design and not matter of a file structure. This is how to work with m-n relationship in a file system and how to get all information from it.

Vladimir Odrljin Received on Thu Mar 22 2007 - 21:46:22 CET

Original text of this message