ON_SerialNumberMap provides a way to map set of unique serial number - uuid pairs to application defined values so that adding, finding and removing serial numbers is fast and efficient. The class is designed to handle several millions of unique serial numbers. There are no restrictions on what order numbers are added and removed. The minimum memory footprint is less than 150KB and doesn't increase until you have more than 8000 serial numbers. It is possible to have an active serial number and an inactive id. More...
#include <opennurbs_lookup.h>
Classes | |
struct | MAP_VALUE |
struct | SN_ELEMENT |
Public Member Functions | |
ON_SerialNumberMap () | |
~ON_SerialNumberMap () | |
ON__UINT64 | ActiveIdCount () const |
ON__UINT64 | ActiveSerialNumberCount () const |
struct SN_ELEMENT * | AddSerialNumber (ON__UINT64 sn) |
Add a serial number to the map. More... | |
struct SN_ELEMENT * | AddSerialNumberAndId (ON__UINT64 sn, ON_UUID id) |
void | Dump (ON_TextLog &text_log) const |
void | EmptyList () |
Empties the list. More... | |
struct SN_ELEMENT * | FindId (ON_UUID) const |
struct SN_ELEMENT * | FindSerialNumber (ON__UINT64 sn) const |
struct SN_ELEMENT * | FirstElement () const |
ON__UINT64 | GetElements (ON__UINT64 sn0, ON__UINT64 sn1, ON__UINT64 max_count, ON_SimpleArray< SN_ELEMENT > &elements) const |
Finds all the elements whose serial numbers are in the range sn0 <= sn <= sn1 and appends them to the elements[] array. If max_count > 0, it specifies the maximum number of elements to append. More... | |
bool | IsValid (bool bBuildHashTable, ON_TextLog *textlog) const |
Returns true if the map is valid. Returns false if the map is not valid. If an error is found and textlog is not null, then a description of the problem is sent to textlog. More... | |
struct SN_ELEMENT * | LastElement () const |
struct SN_ELEMENT * | RemoveId (ON__UINT64 sn, ON_UUID id) |
struct SN_ELEMENT * | RemoveSerialNumberAndId (ON__UINT64 sn) |
ON_SerialNumberMap provides a way to map set of unique serial number - uuid pairs to application defined values so that adding, finding and removing serial numbers is fast and efficient. The class is designed to handle several millions of unique serial numbers. There are no restrictions on what order numbers are added and removed. The minimum memory footprint is less than 150KB and doesn't increase until you have more than 8000 serial numbers. It is possible to have an active serial number and an inactive id.
ON_SerialNumberMap::ON_SerialNumberMap | ( | ) |
ON_SerialNumberMap::~ON_SerialNumberMap | ( | ) |
ON__UINT64 ON_SerialNumberMap::ActiveIdCount | ( | ) | const |
ON__UINT64 ON_SerialNumberMap::ActiveSerialNumberCount | ( | ) | const |
struct SN_ELEMENT* ON_SerialNumberMap::AddSerialNumber | ( | ON__UINT64 | sn | ) |
Add a serial number to the map.
sn | [in] serial number to add. |
If the serial number is valid (>0), a pointer to its element is returned. When a new element is added, every byte of the m_value field is set to 0. If the serial number was already active, its element is also returned. If you need to distinguish between new and previously existing elements, then set an m_value field to something besides 0 after you add a new serial number. The id associated with this serial number will be zero and cannot be found using FindId(). Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
struct SN_ELEMENT* ON_SerialNumberMap::AddSerialNumberAndId | ( | ON__UINT64 | sn, |
ON_UUID | id | ||
) |
sn | [in] serial number to add. |
id | [in] suggested id to add. If id is zero or already in use, another id will be assigned to the element. |
If the serial number is valid (>0), a pointer to its element is returned. When a new element is added, every byte of the m_value field is set to 0. If the serial number was already active, its element is also returned. If you need to distinguish between new and previously existing elements, then set an m_value field to something besides 0 after you add a new serial number. If the id parameter is nil, then a new uuid is created and added. If the id parameter is not nil but is active on another element, a new uuid is created and added. You can inspect the value of m_id on the returned element to determine the id AddSerialNumberAndId() assigned to the element.
Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
void ON_SerialNumberMap::Dump | ( | ON_TextLog & | text_log | ) | const |
void ON_SerialNumberMap::EmptyList | ( | ) |
Empties the list.
struct SN_ELEMENT* ON_SerialNumberMap::FindId | ( | ON_UUID | ) | const |
id | [in] id number to search for. |
If the id is active, a pointer to its element is returned. Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
struct SN_ELEMENT* ON_SerialNumberMap::FindSerialNumber | ( | ON__UINT64 | sn | ) | const |
sn | [in] serial number to search for. |
If the serial number is active, a pointer to its element is returned. Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
struct SN_ELEMENT* ON_SerialNumberMap::FirstElement | ( | ) | const |
The active element with the smallest serial number, or null if the list is empty. Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
ON__UINT64 ON_SerialNumberMap::GetElements | ( | ON__UINT64 | sn0, |
ON__UINT64 | sn1, | ||
ON__UINT64 | max_count, | ||
ON_SimpleArray< SN_ELEMENT > & | elements | ||
) | const |
Finds all the elements whose serial numbers are in the range sn0 <= sn <= sn1 and appends them to the elements[] array. If max_count > 0, it specifies the maximum number of elements to append.
sn0 | [in] Minimum serial number. |
sn1 | [in] Maximum serial number |
max_count | [in] If max_count > 0, this parameter specifies the maximum number of elements to append. |
elements | [out] Elements are appended to this array |
When many elements are returned, GetElements() can be substantially faster than repeated calls to FindElement().
bool ON_SerialNumberMap::IsValid | ( | bool | bBuildHashTable, |
ON_TextLog * | textlog | ||
) | const |
Returns true if the map is valid. Returns false if the map is not valid. If an error is found and textlog is not null, then a description of the problem is sent to textlog.
struct SN_ELEMENT* ON_SerialNumberMap::LastElement | ( | ) | const |
The active element with the biggest serial number, or null if the list is empty. Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
struct SN_ELEMENT* ON_SerialNumberMap::RemoveId | ( | ON__UINT64 | sn, |
ON_UUID | id | ||
) |
sn | [in] If > 0, this is the serial number of the element with the id. If 0, the field is ignored. |
id | [in] id to search for. |
If the id was active, it is removed and a pointer to its element is returned. The element's serial remains active. To remove both the id and serial number, use RemoveSerialNumberAndId(). Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.
struct SN_ELEMENT* ON_SerialNumberMap::RemoveSerialNumberAndId | ( | ON__UINT64 | sn | ) |
sn | [in] serial number of the element to remove. |
If the serial number was active, it is removed and a pointer to its element is returned. If the element's id was active, the id is also removed. Restrictions: The returned pointer may become invalid after any subsequent calls to any function in this class. If you need to save information in the returned SN_ELEMENT for future use, you must copy the information into storage you are managing.
You may change the value of the SN_ELEMENT's m_value field. You must NEVER change any other SN_ELEMENT fields or you will break searching and possibly cause crashes.