// -*- Mode: C++ -*- // GiSTentry.h // // Copyright (c) 1996, Regents of the University of California #ifndef GISTENTRY_H #define GISTENTRY_H #include // for memcpy #include "GiSTdefs.h" #include "GiSTpredicate.h" class GiSTnode; // GiSTcompressedEntry is the compressed format of a key-pointer pair. class GiSTcompressedEntry { public: char *key; int keyLen; GiSTpage ptr; GiSTcompressedEntry(): key(NULL), keyLen(0), ptr(0) {} const GiSTcompressedEntry operator = (const GiSTcompressedEntry c) { key=c.key; keyLen=c.keyLen; ptr=c.ptr; return(*this); } }; // GiSTpenalty is the token returned by the Penalty method. We don't // just use doubles here because it can be useful to use more // complex Penalty comparisons (e.g. to support multivalued Penalties that // break ties in a single value). class GiSTpenalty { public: GiSTpenalty(): amount(0) {} GiSTpenalty(const double d): amount(d) {} virtual double operator = (const double d) { amount=d; return amount; } virtual int operator < (const GiSTpenalty &p) const { if(amountCopy(); compressedEntry.keyLen=CompressedLength(); compressedEntry.ptr=ptr; return compressedEntry; } // Besides decompressing the key, Decompress also sets the pointer. virtual void Decompress(const GiSTcompressedEntry entry) { key=(GiSTobject *)new char[entry.keyLen]; memcpy(key, entry.key, entry.keyLen); ptr=entry.ptr; } // If you have ordered keys, this can be overridden a la qsort's compare virtual int Compare(const GiSTentry& entry) const { return 0; } // access to the protected info GiSTpage Ptr() const { return ptr; } void SetPtr(GiSTpage p) { ptr=p; } GiSTobject *Key() const { return key; } GiSTobjid IsA() const { return GISTENTRY_CLASS; } int IsLeaf() const { return level==0; } int Level() const { return level; } void SetLevel(int l) { level=l; } void SetPosition(int pos) { position=pos; } int Position() const { return position; } GiSTnode *Node() const { return node; } void SetNode(GiSTnode *n) { node=n; } protected: GiSTnode *node; GiSTpage ptr; int position; int level; GiSTobject *key; }; #endif