MCPcopy Create free account
hub / github.com/ImageEngine/cortex / writeUniqueData

Method writeUniqueData

src/IECore/StreamIndexedIO.cpp:2501–2548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2499}
2500
2501uint64_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
2550StreamIndexedIO::Index::WriteInfo StreamIndexedIO::Index::writeUniqueDataCompressed( const char *data, size_t size, bool prefixSize )
2551{

Callers

nothing calls this directly

Calls 6

IOExceptionFunction · 0.85
writeLittleEndianFunction · 0.85
appendMethod · 0.80
insertMethod · 0.80
seekpMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected