6 Replies Latest reply: Dec 2, 2007 6:37 PM by 807603 RSS

    random access file scenario: stuck on how it works?

    807603
      Well, I'm doing an assignment on random access files, and I'm having a little trouble getting my head around what I'm supposed to write to the file. Here's how the assignment goes:

      Implement a hash file structure. The program is to maintain records containing names, addresses and telephone numbers. Use the name field as the key.


      Data Structures and Files
      Data File: Store the record data in a Random Access File containing unsorted records of fixed length. Assume that the data file is too large to fit in memory. Pad the strings in the record to a fixed length.

      Hash Table: Use a hash table in memory as an index into the data file. Use chaining to resolve collisions. You may use the HashTable and SortedList implementations from any lecture notes or lab solutions, but not from the Java class libraries (or other source besides your own creativity).


      Index File: Assume the hash table will be saved on file when processing is complete and will be entirely restored into memory when processing begins again. Don't use a Random Access File for this.

      Now what I'm having trouble with is this idea of writing an index file and a data file. So far i've implemented a hash table, which is implemented as an array of linked lists, which store nodes, which store records, a key (the name), and the next node.

      My problem is, I'm really stuck as to how to write the files :S. from what I understand, my index file will be a list of indexes and record numbers, and my data file will be sets of addressses (strings padded out to a set length) as bytes. As far as I know i'm supposed to write these strings to a random access file, and the user should be able to retrieve it from the access file by searching for the name (which is the key) in the hash table. But i don't understand if i'm storing my addresses in record objects how im supposed to associate my byte values which are strings with the records. Help!!

      Edit: Would i be storing in my record the byte address instead of the actual record? So instead of my record being String name, string address, string phnumber, would it be int position, key name? is that how it works?

      Edited by: Cymae on Dec 2, 2007 3:11 PM
        • 1. Re: random access file scenario: stuck on how it works?
          796440
          Your index file can contain either the byte position or the record position, since the records are of fixed length. It looks to me like you'd have something like this:
          // Data file
          Joe     123 Main St.      111-222-3333
          Fred    456 Secondary St. 444-555-6666
          Ed      789 Tertiary St.  777-888-9999
          
          
          // Index file
          Joe 0
          Fred 1 or 1 * record size
          Ed 2 or 2 * record size
          • 2. Re: random access file scenario: stuck on how it works?
            807603
            Ok, and how does that fit in with my hash table and record object? I'm sorry, i know this sounds stupid but im really confused

            and the files have to be in byte...not strings printed to a file (just to clarify everyone understood that)

            Edited by: Cymae on Dec 2, 2007 3:47 PM
            • 3. Re: random access file scenario: stuck on how it works?
              796440
              Cymae wrote:
              Ok, and how does that fit in with my hash table and record object?
              What do you mean "How does it fit in"? It fits in as described by the assignment. The index file stores the hashtable and the data file stores the record objects.
              and the files have to be in byte...not strings printed to a file (just to clarify everyone understood that)
              I have no idea what you're saying here. Sounds like you need to talk to you instructor and get clarification on your requirements.
              • 4. Re: random access file scenario: stuck on how it works?
                807603
                ok...so i just whack the hash table as one big thing into my index file, and then use the output stream to write a string of "name" "address" "phone number" into my data file?

                So what does my hash table store? it stores the index of the records i have in the data file?
                • 5. Re: random access file scenario: stuck on how it works?
                  796440
                  Cymae wrote:
                  ok...so i just whack the hash table as one big thing into my index file, and then use the output stream to write a string of "name" "address" "phone number" into my data file?
                  If I understood your assignment correctly, yes.
                  So what does my hash table store? it stores the index of the records i have in the data file?
                  Yes. The hash table--and the index file where you store it--tells you where in the file to find, for instance, "Mary".
                  • 6. Re: random access file scenario: stuck on how it works?
                    807603
                    ahhhh. Okay. been doing it wrong. My hash table was storing the actual records, which is bad. In fact, i don't even need the record class.

                    Thanks!! <3