Subject: What do you mean about this data structure
From: laurent couraud
Date: Tue, 8 Mar 2005 19:34:02 +0100
Hi,
First sorry for my bad English. I'm French
Use fixed font to read this message please.
I try to found the most efficient way to store CRE form of
expression. In memory usage and speed access.
"Classic" form of expression :
x1*(x2^2+3*x3)+x1^2*x2^3-x1^(3*n)
If I have well understood CRE form then the above expression correspond to:
x1 , 1 ,( x2 , 2 , 1 ,( 0 ,( x3 , 1 , 3 , nil), nil),2
,(x2 , 3 , 1 , nil),( n , 1 , 3 , nil), -1 ,nil
| | | | | | | | | | | |
| | | | (name,power,coeff,next) | |
| | | | | | | | | | | |
| | | | | | |
| | | | | | | | | | | |
| | | | (power ),coeff,next
| | | | | | | | | | | |
(name,power,coeff,next) |
| | | | | | | | | | | |
| |
| | | | | | | | | | |
power,(coeff ), next
| | | | | | (name,power,coeff,next), | |
| | | | | | | | |
| | | | | (power,(coeff ), next),|
| | | | | | |
| | (name,power,coeff,next), |
| | | |
name,power,(coeff ), next
DEFINITION: NCRE = (name,power,coeff,next).
The field "name" is a value returned by a hash table.
The field "next" can point only on "object" that contains
(power,coeff,next) then => DEFINITION: PCRE = (power,coeff,next)
"power" can be only numeric or of type NCRE If value of numeric power
is zero we have no need to store this value then => DEFINITION: CRE =
(coeff,next)
Then field "next" can be only of type PCRE or CRE
The field "coeff" and "power" can be only numeric or of type NCRE If
"power" or "coeff" is numeric we never have a next object then =>
DEFINITION: LCRE = (coeff)
abstract:
name is the index where the real name is stored in a hash table
power can be only LCRE or NCRE
coeff can be only LCRE or NCRE
next can be only PCRE or CRE
Data structure to store NCRE, PCRE, LCRE, CRE
The array to store the NCRE can be like this:
ncreidx ncreidx
| |
[null , [name , power , coeff , next] , [name , power , coeff ,
next] , .........]
|_____________ ____________| |_____________ ____________|
\/ \/
NCRE NCRE
If memory address returned by memory allocation is even,
we can increment it to force it to be odd. In other word the
real first used address of the array must be odd. In this way the
pointer for NCRE will be always odd
ncreidx is always odd.
The array to store the LCRE and PCRE can be like this:
lcreidx pcreidx lcreidx
| | |
[[coeff ] , [power , coeff , next] , [coeff ] , .......]
|__ __| |_________ _________| |__ __|
\/ \/ \/
LCRE PCRE LCRE
Like for NCRE we can force this array to start we a even memory
address. In this way :
lcreidx is always even.
pcreidx is always odd.
The array to store the CRE can be like this:
creidx creidx
| |
[[coeff , next ] , [coeff , next] , ......
|______ ______| |_____ _____|
\/ \/
CRE CRE
creidx is always even.
With this data structure we can know the type of "object" that
pointer give only by testing the Less Significant Bit (LSB) of the
pointer.
For example :
Because coeff can be only of type LCRE or NCRE
We can know what type is like this :
If LSB(coeff)=1 then coeff is an NCRE
Else if not (coeff=0) then coeff is a LCRE
It is exactly the same for power
And for next we have :
If LSB(next)=1 then next is a PCRE
Else if not (next=0) then next is a CRE