Skip to content

Commit

Permalink
updates to file dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
elidwa committed Oct 27, 2024
1 parent 07e7561 commit 0577149
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/geo/RasterFileDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ uint64_t RasterFileDictionary::add(const string& fileName, bool sample)
const char* RasterFileDictionary::get(uint64_t fileId)
{
const char* fileName = "";
uint32_t index;

/* Mask upper 32 bits to get index into vector */
const uint32_t index = static_cast<uint32_t>(fileId & 0xFFFFFFFF);
if(index < fileVector.size())
if(getIndex(fileId, index))
{
/* Mask upper 32 bits to get index into vector */
fileName = fileVector[index].c_str();
}

return fileName;
}

Expand All @@ -96,9 +97,9 @@ const char* RasterFileDictionary::get(uint64_t fileId)
*----------------------------------------------------------------------------*/
void RasterFileDictionary::setSample(uint64_t sampleFileId)
{
/* Make sure sampleFileId is valid */
const char* fileName = get(sampleFileId);
if(fileName && *fileName != '\0')
uint32_t index;

if(getIndex(sampleFileId, index))
{
sampleIdSet.insert(sampleFileId);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/geo/RasterFileDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class RasterFileDictionary
/*--------------------------------------------------------------------
* Constants
*--------------------------------------------------------------------*/
const uint64_t UPPER32_MASK = 0xFFFFFFFF00000000;
const uint32_t INDEX_MASK = 0xFFFFFFFF;

/*--------------------------------------------------------------------
* Typedefs
Expand All @@ -64,6 +66,7 @@ class RasterFileDictionary
const char* get (uint64_t fileId);
void setSample(uint64_t sampleFileId);
void clear (void);
size_t size (void) const { return fileVector.size(); }

const std::set<uint64_t>& getSampleIds(void) const;
RasterFileDictionary copy(void);
Expand All @@ -74,6 +77,16 @@ class RasterFileDictionary
* Methods
*--------------------------------------------------------------------*/

/* Force inline by implementing here */
bool getIndex(uint64_t fileId, uint32_t& index)
{
if((fileId & UPPER32_MASK) == keySpace)
{
index = static_cast<uint32_t>(fileId & INDEX_MASK);
return index < fileVector.size();
}
return false;
}

/*--------------------------------------------------------------------
* Data
Expand Down

0 comments on commit 0577149

Please sign in to comment.