SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Key Class Reference
Collaboration diagram for Key:
Collaboration graph
[legend]

Public Member Functions

 Key ()
 Default constructor. Sets key_format and key_data to nullptr.
 
 Key (std::uint32_t capacity)
 Constructor to create a Key object with key_data field of the size of some capacity and sets key_format to nullptr.
 
 Key (SearchKeyFormat *key_format, Data *key_data)
 Constructor given appropriate key_format and key_data.
 
 ~Key ()
 Destructor.
 
SearchKeyFormatgetKeyFormat ()
 Getter function for key_format.
 
DatagetKeyData ()
 Getter for key_data.
 
void setKeyFormat (SearchKeyFormat *new_format)
 Setter for key format.
 
void setKeyData (Data *new_data)
 Setter for key_data.
 
void setKeyFromValues (std::vector< void * > values)
 sets a key data field to the values from the passed vector of void * pointers.
 
void setKeyFromRecord (Record *rec)
 sets a key data field to the vaules from the passed record
 
Comp compare (Key other)
 Compare function for comparing keys.
 
bool compareDifferent (Key *other_key, std::vector< Comp > comp_list)
 Compare function for comparing keys from differing relations, but with the same format. Takes in comparison operator and returns boolean.
 
bool compareDifferent (Key *other_key, Comp comp_op)
 Compare function for comparing keys from differing relations, but with the same format. Takes in comparison operator and returns boolean.
 
Comp compare (char *other, std::uint32_t size)
 Compare function for comparing keys, one of which is serialized bytes of data.
 
HashVal hash ()
 Hash function for hashing key, as raw bytes of data.
 

Private Attributes

SearchKeyFormatkey_format
 
Datakey_data
 

Constructor & Destructor Documentation

◆ Key() [1/2]

Key::Key ( std::uint32_t  capacity)

Constructor to create a Key object with key_data field of the size of some capacity and sets key_format to nullptr.

This constructor is useful for creating a Key object that can be used to extract Key data from Records or off page data. Pass in a capacity value that is big enough to store the largest Key data in this case.

Precondition
: capacity is a valid size (MAX_RECORD_SIZE or less)
Postcondition
: key_data points to a new Data object of capacity size and key_format is set to nullptr
Parameters
capacitytotal capacity of the Data part of the key

◆ Key() [2/2]

Key::Key ( SearchKeyFormat key_format,
Data key_data 
)

Constructor given appropriate key_format and key_data.

Precondition
Valid key_format and key_data are provided as input. key_data is in serialized, format corresponding to key_format.
Postcondition
key_format and key_data are set to the provided inputs.
Parameters
key_formatformat of the key.
key_dataData* key_data that stores the Key data.

◆ ~Key()

Key::~Key ( )
inline

Destructor.

Precondition
None.
Postcondition
key_data is not deallocated.

Member Function Documentation

◆ compare() [1/2]

Comp Key::compare ( char other,
std::uint32_t  size 
)

Compare function for comparing keys, one of which is serialized bytes of data.

Precondition
Valid serialized key is provided as input.
Postcondition
If Key is less than other, LESS is returned. If Key is equal to other, EQUAL is returned. If Key is greater than other, GREATER is returned. INVALID_TYPE is returned if there is any error in key format.
Parameters
otherThe serialized key to be compared to.
sizeThe size of the serialized key.
Returns
LESS if Key is less, EQUAL if Key is equal, GREATER if Key is greater than other. INVALID_TYPE if there is any error in key format.

◆ compare() [2/2]

Comp Key::compare ( Key  other)

Compare function for comparing keys.

Precondition
Valid Key object is provided as input.
Postcondition
If the key_formats are different, INVALID_TYPE is returned. If Key is less than other, LESS is returned. If Key is equal to other, EQUAL is returned. If Key is greater than other, GREATER is returned.
Parameters
otherThe Key to be compared to.
Returns
LESS if Key is less, EQUAL if Key is equal, GREATER if Key is greater than other. INVALID_TYPE if there is any error in key format.

◆ compareDifferent() [1/2]

bool Key::compareDifferent ( Key other_key,
Comp  comp_op 
)

Compare function for comparing keys from differing relations, but with the same format. Takes in comparison operator and returns boolean.

Precondition
Valid Key object is provided as input. Keys have the same number of fields and fieldtypes.
Postcondition
Neither key object is modified.
Parameters
other_key.The Key to be compared to.
comp_op.Comparison operator for all fields.
Returns
true if comparison is true on all fields, false otherwise.

◆ compareDifferent() [2/2]

bool Key::compareDifferent ( Key other_key,
std::vector< Comp >  comp_list 
)

Compare function for comparing keys from differing relations, but with the same format. Takes in comparison operator and returns boolean.

Precondition
Valid Key object is provided as input. Keys have the same number of fields and fieldtypes.
Postcondition
Neither key object is modified.
Parameters
other_key.The Key to be compared to.
comp_list.Vector of Comp types corresponding to each field.
Returns
true if comparison is true on all fields, false otherwise.

◆ getKeyData()

Data * Key::getKeyData ( )

Getter for key_data.

Precondition
None.
Postcondition
key_data is returned.
Returns
Data* to the key_data of the Key.

◆ getKeyFormat()

SearchKeyFormat * Key::getKeyFormat ( )

Getter function for key_format.

Precondition
None.
Postcondition
key format is returned.
Returns
format of the Key.

◆ setKeyData()

void Key::setKeyData ( Data new_data)

Setter for key_data.

Precondition
Valid Data* is provided as an input.
Postcondition
key_data is set to new_data. The previous data is not deleted.
Parameters
new_dataNew Data* key_data is set to.

◆ setKeyFormat()

void Key::setKeyFormat ( SearchKeyFormat new_format)

Setter for key format.

Precondition
Valid key_format is provided as an input.
Postcondition
key_format is set to given key_format.
Parameters
new_formatNew key_format to be set.

◆ setKeyFromRecord()

void Key::setKeyFromRecord ( Record rec)

sets a key data field to the vaules from the passed record

Precondition
: the Key has been initialized with non null data and KeyFormat values, and the passed record is from a Relation with a matching schema. The key_data field has appropriate capacity to store the copied values from the passed record.
Postcondition
: the data field is set to the field values copied to the passed rec
Parameters
rec is pointer to the Record from which the key data fields should be set
Exceptions

InvalidFormatKey if the Key and the Record format are incompatable or if the Key has not been initialized with a KeyFormat

Exceptions

InvalidCapacityKey if the Key does not have enough capacity to store the key field values from the passed record

◆ setKeyFromValues()

void Key::setKeyFromValues ( std::vector< void * >  values)

sets a key data field to the values from the passed vector of void * pointers.

Precondition
: the Key has been initialized with non null data and KeyFormat values, and the passed vector matches the Relation schema. The key_data field has appropriate capacity to store the values.
Postcondition
: the data field is set to the field values copied to the passed rec
Parameters
values vector of void * corresponding to the values to be compared to this key.
Exceptions

InvalidFormatKey if the Key has not been initialized with a KeyFormat

Exceptions

InvalidCapacityKey if the Key does not have enough capacity to store the key field values from the passed record

Member Data Documentation

◆ key_data

Data* Key::key_data
private

Data of the Key. The object (not the pointer) is never modified in scope of this object.

◆ key_format

SearchKeyFormat* Key::key_format
private

format of the Key.


The documentation for this class was generated from the following file: