tags:

views:

147

answers:

3

Dictionaries usually has an index and a data file. I'm writing a dictionary application as a hobby project. I'm confused about how to read the offset file in .NET. The index file is of 4-5 MB size. What is the most efficient way to fetch the offset/length value of a word.

EDIT: I need to know only how to read offset file if I have a word to search. ie how to search the index file for a word so that I can get the subsequent 8 bytes

+3  A: 

Stream.Seek(long offset, SeekOrigin origin) will be usefull to get to the offset.

Fabian Vilers
A: 

System.IO.BinaryReader has a ReadUInt32 method that reads an unsigned int. It also has different methods for reading binary files.

rslite
+2  A: 

4-5 megabytes for the index? That's nothing. Read the entire thing into a byte array and with it as a MemoryStream or more appropriately, parse the entire contents into appropriate data structures for quick searching (has, b-tree, etc).

plinth
i cant parse it unless I know the search key. What to do? I have to search the entire 5MB data everytime I need to get a word. then take the offset and length from subsequent bytes and fetch from the actual data file? But how to handle search keys that match substrings of a word in the index file?
Mahatma
Parse the dictionary, not the index. The dictionary is entirely the right size to read into an array/memorystream. Once you've parsed the dictionary you can put it into a more palatable form. Note that unless the dictionary format or contents change, this is something you do precisely once.
plinth