Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RECNO_OF_INDEX()

Status
Not open for further replies.

foxmuldr3

Programmer
Jul 19, 2012
166
US
If we use RECNO() we get the record number of the row in the table. Is there an equivalent function which gives us the record number of the current record's entry in the current index/tag?

Code:
RECNO  cField
  1    ZEBRA
  2    HIPPO
  3    DOVE

INDEX ON cField TAG MAIN

Code:
ENTRY RECNO  cField
  1     3    DOVE
  2     2    HIPPO
  3     1    ZEBRA

Looking for a way to obtain the index ENTRY number for any given RECNO in the table.

Thank you! :)

Best regards,
Rick C. Hodgin
 
This question is for Visual FreePro, I assume. You want to implent updating CDX when writing to DBF. There should be something possible, of course, as VFP does that, but an index tree strucutre is there to lookup the RECNO by the field value (or more general by the index expression value), not the inverse. It's optimised to do what it does, and that is not supporting a reverse lookup. I assume VFP does not have suche a function to get index node position by dbf RECNO(), but determines nodes belonging to the index expression value, the old value, as that is the way to find a node. Of course the old expression is searched and when found the node needs to be moved to the tree position representing the new value, perhaps the node is just deleted and a new node is created, as only in very few cases the index tree won't change, when the new value of the dbf field sorts in the same order position.

You might be interested in a more detailed description about the index file structure, than what you can get from the VBFP help. Calvin Hsia's showed how to interpret an index and construct index expression values from it in a blog post here:

This prg decodes a cdx and so you see at least some of the inner workings.

You might find your own way of getting at the ENTRY, index node position or something equivalent on your own.

I would look into open source implementations of DBF read/writers including CDX. To my knowlegde there is no full file specification published about the CDX or IDX, the DBF is pretty much known down to each single bit, but with CDX files, you will need to adapt to experimentally or roll your own.

Something I just googled:
Bye, Olaf.
 
On thing you could do to experiment how cdxes are composed and what changes in them:

Index a dbf with c(1) field containing 'a','b','c' copy that cdx, change 'c' to 'e' and copy that cdx to see what changed (in this case no sort order is changed), change 'b' to 'z' and copy that cdx to see what changed now.

I think such comparisons of cdx stages will be very informative. I know you can come up with even cleverer ideas.

Bye, Olaf.
 
Actually, I was looking to see if there was some functionality in VFP I didn't know about. :) I have a need to know the entry number in the current index tag and am forced presently to use a brute force method to obtain it.

I appreciate your responses, Olaf.

Best regards,
Rick C. Hodgin
 
I know you can come up with even cleverer ideas."

I honestly didn't think one could do that (come up with "CLEVERER" ideas, but rather "MORE CLEVER" ideas). However, I did a search and found that "cleverer" *IS* actually a word!! I don't think I've ever heard that word used in my entire life. Things have always been "more clever" in my world. But that would introduce a question in use:

"I know you can come up with more clever ideas."

Does it mean:
(1) I can come up with more ideas, each of which are equally clever
(2) I can come up with more ideas, some of which are even more clever than the original

?? I hate English. :) Why? As a knight, of eight feet of height, and as a feat of prowess, I ate crow on through the night, until dawn, when I saw Don, who brought me peace, and a piece of pie, that my eye did spy. Oh my, oh my.

Best regards,
Rick C. Hodgin
 
There isn't an inbuilt function. As a CDX is not a list of records but a btree of index nodes, there also is not such a position comparable to RECNO(). There surely is a byte offset where the corresponding node starts. There are parent/child nodes, siblings but I doubt there is a sequence of nodes in sort order. Instead to find the next record in index order VFP uses an apporach equally to a rushmore optimised LOCATE for indexexpression > current value.

Once VFP is at a certain CDX node, that next node might simply be the sibling node, unless there are no further siblings, then child node, unless there are no further child nodes, then parent node siblings etc.

Overall the structure is a tree node structure and that by definition rather has pointers to other nodes than a node number, otherwise a single new record would mostly need a reorganisation of all index nodes, that's not practical, is it?

Bye, Olaf.
 
...that's not practical, is it?"

Depends on several factors. Modern hard drives write about 50 MB/s. If your indexes are a few hundred megabytes or less, it's far more practical to have a simple .IDX structure as the indexes can be maintained in memory and completely re-written at exit, or in a background thread as necessary. Plus, they are trivial to utilize in a variety of ways. As you indicate, CDX files are complex.

If the indexes need to be much larger than a few hundred megabytes, then a single system for maintaining both data, indexes, and executing code seems an odd combination unless you have relatively simple data access by only a handful of users, at which point you're back to the idea of taking a few extra seconds here or there not really causing an issue in the system.

Only in the case of high-speed, high-traffic cases does the CDX design seem to make sense. And I can actually think of some cleverer ideas than that which also remain simple.

Best regards,
Rick C. Hodgin
 
Sorry to digress, and just for the record: "Cleverer" is perfectly correct.

The mormal usage is to add -er to make a comparitive (and -est for a superlative), if the adjective is a single syllable, or if it is two syllables, with the last syllable being -y, -le, or -er. "Clever" clearly comes into that last category.

There are quite a few other adjectives that take -er but don't follow these rules. In general, it's a question of euphony rather than grammer, that is, you use -er unless it sounds clumsy to do so. In other cases, you would precede the adjective with "more".

(Source for the above: Fowler's Modern English Usage.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I don't know how you think FoxPro makes use of CDXes. CDXes are not complex, they are compound, composed of several IDXes inside and compact, compressed, which also helps a lot in making them more performant than IDX.

VFP does neither read in whole IDX nor TAGs of a CDX into memory, as with DBFs, VFP reads just as much nodes, as it needs to do a certain SEEK. Even if you display a whole DBF in a browse or grid, the grid control (on which the browse window also is based) only reads as much DB records as needed to fill the visual area. And also does only as much locates in an index to locate as many records as needed.

You can watch what is really loaded from the files by sysinternal tools or wireshark network sniffer, to see yourself what happens behind the scenes.

I see how in memory indexes would be much faster, but they are already accelerating mutli user access. What VFP caches of CDXes in memory for a local VFP session I don't know, I assume you know tools, which cvould help you find out. Again you could watch network packets and if there is no network traffic caused by VFP you know it's reading cached data and/or indexes.

As much as you can accelerate with whatever new index formats, you have to do CDXes for compatibility or you have to limit compatibility and do an index conversion. Should be easy enough, as indexes can be computed from DBF/FPT data in the normal case.

I fear I can't help you any further.
 
I know this is very off topic, off thread really, but I do like that demonstration of the anomalies in English:

As a knight, of eight feet of height, and as a feat of prowess, I ate crow on through the night, until dawn, when I saw Don, who brought me peace, and a piece of pie, that my eye did spy. Oh my, oh my.

At school we're given a rule: I before E, except after C, which is supposed to help people spell... except there are, perhaps, as many exceptions as words that follow the 'rule'

To name but one: their - often misspelt version of they're.

Another good one is yaw and your and you're

Lastly, a puzzle : can you think of a sentence which is grammatically correct and has the word 'and' in it five times consecutively?


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
can you think of a sentence which is grammatically correct and has the word 'and' in it five times consecutively?"

I said to the class, "In this example, you'll never get from A to B unless you construct C, and do ... what? Any guesses?"

And in response my star pupil said to me, "And, and, and, and, and ... *sigh* I don't know, teacher. I'm sorry. What's the answer?"

:)

Best regards,
Rick C. Hodgin
 
It's a desciption of a pub sign, newly painted - where the Landlord of the pub is complaining to the signwriter:

His pub is called the 'Pig and Whistle' and he rightly compains that the spacing between words is awry:

'The space between Pig and and and and and and Whistle is different!'

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
There are 10 kinds of people in the world, those who understand binary and those who don't."

The top 10 list of things I hate about C:

#9 - ...

Best regards,
Rick C. Hodgin
 
Don't get me started on C#... I hate it, hate it, hate it.

It's nearly clever, nearly good, nearly quick... but not if you have a real world app to develop...


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
In regard to 'cleverer':

Adding -er to a positive to get the comparative is rather common in both German and English grammar, isn't it? And as clever also is used in German as a foreign word and has the comparative 'cleverer', I wrote that.
By the way: For the german superlative you typically add the word 'am ' in front of the adjective and add a suffix -sten instead of -est, which also is quite similar, besides adding 'am'. We have very few irregular cases, and none of them uses 'more' to create the comparative, with the exception of the adjective 'many' itself, of course. This is "many, more, most" in English and "viele, mehr, am meisten" in German.

I am making enough mistakes - not only typos - to show this was rather a lucky strike than knowledge.

Thanks, Mike, for defending. But I am not offended at all, if you correct my language, even if it is correct, but uncommon.

Bye, Olaf.
 
To be clear, my post was in reference to my own ignorance, and in being taught something by Olaf. It was not to demean him or his post in any way, but rather to point out that I have never heard that word before. I meant that fact to indicate I was lacking in knowledge only.

Best regards,
Rick C. Hodgin
 
No need to demean yourself now, Rick.

(By the way another new word for me: demean).

I appreciate it anyway, as it means you point out I use uncommon english, if you did that by accident or not.

Using uncommon language is a very common mistake for someone, who is not having personal contact to native english speakers, besides forum visits. And many here also are not native english speakers. In a personal dialog you would be corrected more often, I assume, and my english would improve better. In forums this is taking longer to point out and often not worth the effort, of course.

A thing I do to brush up my english is watching uk/us tv series in their original form.

So anyway, I am happy.

Bye, Olaf.
 
Calling oneself ignorant isn't necessarily a demeaning comment either. It can be, but in most cases it's just a statement of unknown things. I am woefully ignorant of medicine, for example, having almost no knowledge as I've never studied it. It doesn't mean I'm demeaning myself to say that, or that I'm in some way less of a person than another who is skilled in medicine. It just means it's not something I know.

It's why God made all of us. Each of us have skills in various areas. Some overlap. Some don't. But between all of us, we have what we need to get by.

And for the record ... I am ignorant of far more than I am "norant" of. Oh, how I hate English. I look forward to hearing Heaven's language someday though, that's for sure.

Best regards,
Rick C. Hodgin
 
Olaf,

Your English is nearly always top rate (first class, prime quality, non pareil). I, for one, rarely have any difficulty understanding you (or, if I do, it's usually a FoxPro issue, not an English one).

However, you do frequently make one mistake that really bugs (irritates, annoys) me: putting an apostrophe in the possessive of "it". In correct English, it's means it is. It does not mean that something "belongs to it". So, the following in incorrect: "I opened the table to check it's structure". You should say "its structure".

I hope you don't mind me pointing this out. In fact, I've recently noticed that many native English-speakers are making the same mistake. It's not terrible; it rarely changes the meaning of what they want to say. But it does show their ignorance.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Ok, Mike, I'll pay attention to that.

"Its" is an exception, isn't it? I am right in referring to your posts as "Mike's posts", not "Mikes posts", right? In german it would indeed be the latter, no apostrophe, unless someone's name ends with s, eg you would write Thomas' posts in German and Thomas's posts in English, wouldn't you? So "its" is an exception to distinguish it from "it's", isn't it?

And you're friendly with me. Rereading my posts, I also have come across mistakes as writing "they're" instead of "their" or something in that range of errors, which cannot be counted as a typo anymore. Not only once. Or using "by" instead of "with" or "at", as it sounds so similar to the german "bei", a typical german mistake.

I never ordered a steak by saying "I become a steak", though.

Bye, Olaf.







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top