473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Indexing of file in C++

151 100+
I am trying to index the flat file in order to speed up the searching keyword. How this can be done efficiently? Thanks in advance

Manish
Mar 20 '09 #1
6 6908
weaknessforcats
9,208 Expert Mod 8TB
Read each record of the file and create an STL pair<> object containing the key and the offset of the record from the beginning of the file. Insert the pair<> object into a map<> container.

To access by key, you reas the map<> to get the offset and then read the file and fetch the record at that offset.
Mar 20 '09 #2
Man4ish
151 100+
@weaknessforcats
I think for this whole map need to roll but data structure like B tree is used less comparison will be used but i don't know how to use it.
Mar 21 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
A map<> is a B tree. There is a structure there already. It is the pair<> object.

Here is your file:

Hello
world

The first letter of each word is the key:

H offset 0
w offset 5

Create pair objects with H 0 and w 5.

Insert these in a map<>

To locate world, search the map for w as the key. You will get yout pair object returned ( w 5). Now read your file by doing a seek to 5 and then a read.
Mar 22 '09 #4
Man4ish
151 100+
@weaknessforcats
Thanks, but i have one confusion why value of w is 5. and also if there are two values with lilke water and world then there may be ambiguity.How to overcome that pblm.
Mar 22 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
Hello occupies positions 0,1,2,3,4. world starts in position 5. However, if world is another record, then there will be one or two line control characters after hello. That would start world in position 7 or 8.

The only way to know is to read your file and do a tell on the first letter of each word. Then create your pair<> with the key to that word plus the offset you got from the tell.

This read pass of the disc file to get the offsets and puttting them in a map<> container as pair<> objects is called creating an index.

If you have multiple words with the same key, then use a multimap<>. Then when you access the multimap<> using a key, you have to call both the lower_range and upper_range methods. multimap<>::lower_range returns an interator to the lowest positioned word with that key. multimap<>::upper_range returns an iterator that is one beyond that highest positioned occurrance of the key.

You then use these two iterators as you wouild begin() and end() to iterate the words between those two values. You will get all of the words with that key. Your loop must choose which one it wants.
Mar 22 '09 #6
Man4ish
151 100+
@weaknessforcats
Thank you very much for you answer.
Mar 24 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jay | last post by:
Hello all. I've recently transferred our web sites from a Windows2000 server to a Windows2003 server. The transfer went almost flawless until I noticed that our search function isn't working...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
3
by: jliusolar | last post by:
Hi I am trying to figure out why an application get this error when I am trying to open the application's asmx file from localhost. I don't have indexing service running(it set as manual and not...
1
by: Byron | last post by:
Hey, I'm fussing around with a first attempt at using IIS6's indexing service for a web site search page. The trouble is, my site, while not using a database, is largely dynamic, with much of...
10
by: Lyle Fairfield | last post by:
By default mdb etc files are not searched by Indexing Service. The default can be changed in Windows XP Pro using Group Policy. I can find no suggested way to make the change in the Windows XO...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
0
by: rclark30 | last post by:
Hello to everyone out there. I am a non SQL person TRAPPED in a nightmare! The long short is we have a CRM 3.0 database that is running in SQL 2005 on a Windows 2003 SP1 Server. (HP ProLiant ML350...
2
by: svchosthunter | last post by:
I m working on a web project and I need do file content searching on DOC and PDF . Due to some reason I cant use windows indexing service How I can do it with out crawling each and every...
2
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.