------------------------------------------------------------------------------
| 177 | |
| 178 | //------------------------------------------------------------------------------ |
| 179 | vtkIdType vtkDistributedGraphHelper::GetVertexOwnerByPedigreeId(const vtkVariant& pedigreeId) |
| 180 | { |
| 181 | vtkIdType numProcs = this->Graph->GetInformation()->Get(vtkDataObject::DATA_NUMBER_OF_PIECES()); |
| 182 | if (this->VertexDistribution) |
| 183 | { |
| 184 | return (this->VertexDistribution(pedigreeId, this->VertexDistributionUserData) % numProcs); |
| 185 | } |
| 186 | |
| 187 | // Hash the variant in a very lame way. |
| 188 | double numericValue; |
| 189 | std::string stringValue; |
| 190 | const unsigned char *charsStart, *charsEnd; |
| 191 | if (pedigreeId.IsNumeric()) |
| 192 | { |
| 193 | // Convert every numeric value into a double. |
| 194 | numericValue = pedigreeId.ToDouble(); |
| 195 | |
| 196 | // Hash the characters in the double. |
| 197 | charsStart = reinterpret_cast<const unsigned char*>(&numericValue); |
| 198 | charsEnd = charsStart + sizeof(double); |
| 199 | } |
| 200 | else if (pedigreeId.GetType() == VTK_STRING) |
| 201 | { |
| 202 | stringValue = pedigreeId.ToString(); |
| 203 | charsStart = reinterpret_cast<const unsigned char*>(stringValue.c_str()); |
| 204 | charsEnd = charsStart + stringValue.size(); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | vtkErrorMacro("Cannot hash vertex pedigree ID of type " << pedigreeId.GetType()); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | unsigned long hash = 5381; |
| 213 | for (; charsStart != charsEnd; ++charsStart) |
| 214 | { |
| 215 | hash = ((hash << 5) + hash) ^ *charsStart; |
| 216 | } |
| 217 | |
| 218 | return hash % numProcs; |
| 219 | } |
| 220 | VTK_ABI_NAMESPACE_END |