| 2499 | } |
| 2500 | |
| 2501 | uint64_t StreamIndexedIO::Index::writeUniqueData( const char *data, size_t size, bool prefixSize ) |
| 2502 | { |
| 2503 | m_hasChanged = true; |
| 2504 | |
| 2505 | /// Find next writable location |
| 2506 | uint64_t loc; |
| 2507 | |
| 2508 | // compute hash for the data |
| 2509 | MurmurHash hash; |
| 2510 | hash.append( data, size ); |
| 2511 | |
| 2512 | if ( size >= UINT32_MAX ) |
| 2513 | { |
| 2514 | throw IOException( "StreamIndexedIO: Data size too long!" ); |
| 2515 | } |
| 2516 | uint32_t clampedSize = size; |
| 2517 | size_t totalSize = size; |
| 2518 | |
| 2519 | if ( prefixSize ) |
| 2520 | { |
| 2521 | totalSize += sizeof( clampedSize ); |
| 2522 | } |
| 2523 | |
| 2524 | // see if it's already stored by another node.. |
| 2525 | std::pair< HashToDataMap::iterator,bool > ret = m_hashToDataMap.insert( HashToDataMap::value_type( std::pair< MurmurHash,uint64_t>(hash,totalSize), 0 ) ); |
| 2526 | if ( !ret.second ) |
| 2527 | { |
| 2528 | // we already saved this data, so we dont save any additional data |
| 2529 | return ret.first->second; |
| 2530 | } |
| 2531 | |
| 2532 | /// New data, find next writable location. |
| 2533 | loc = allocate( totalSize ); |
| 2534 | ret.first->second = loc; |
| 2535 | |
| 2536 | /// Seek 'write' pointer to writable location |
| 2537 | m_stream->seekp( loc, std::ios::beg ); |
| 2538 | |
| 2539 | if ( prefixSize ) |
| 2540 | { |
| 2541 | writeLittleEndian( *m_stream, clampedSize ); |
| 2542 | } |
| 2543 | |
| 2544 | /// Write data |
| 2545 | m_stream->write( data, size ); |
| 2546 | |
| 2547 | return loc; |
| 2548 | } |
| 2549 | |
| 2550 | StreamIndexedIO::Index::WriteInfo StreamIndexedIO::Index::writeUniqueDataCompressed( const char *data, size_t size, bool prefixSize ) |
| 2551 | { |
nothing calls this directly
no test coverage detected