What is the definition for invalid nodes

If the child node is unknown, or not valid, what is the definition ? Is it null, -1 , 0 etc ? I seem to get some strange numbers (434 if NumNodes is 431 for example).

Could it possible to set all "invalid" nodes to -1 ?

NextSibling, PrevSibling, Parent, FirstChild etc.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
john's picture

Re: What is the definition for invalid nodes

It looks like it's not a problem to use index number of -1 to indicate null, rather than a valid index number to a null record.

I made the change, and updated the sample .bin files.

So, any code that is reading the blob must take care to check for -1 before using an index number. This is true for Object Reference fields, and it is also true for Object entries in collections (Lists and Maps).


john's picture

Re: What is the definition for invalid nodes

You are getting ahead of me! :-) I haven't yet had a chance to explain how null references work.

Right now, all fields which are 'reference' fields have a valid index number, even if it's just the index number to the null record.

It's possible that null references could just use -1. I will take a look. That will mean that reference fields will have one of two values: -1 to indicate null, or else a valid index number. So, the programmer will have to remember that the index number has to be checked for -1 before trying to use it to look up the record offset from the index, but that might be easier to use than the alternative.


So does the null record have

So does the null record have a special index number ? If so, then it is easy enough to feed that into the node tt and node class anyway. I use -1 to indicate a "null" node for the tt and if someone requests an invalid node for a property I just return the [invalid] node. So this fits in perfectly anyway.

I would hope to hide the memptr stuff away from the programmer by being able to expose the node classes quickly enough, so all node stuff (next child etc) would simply be handled by going node:first-child:text etc


john's picture

Re: special index number

No, the null record didn't have a special index number. Now it does: -1. :-)


Excellent ;) The parseunit

Excellent ;)

The parseunit and node already use -1 as the invalid node, so this fits in just perfectly.