MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / find

Method find

dependency/densecrf3d/src/permutohedral.cpp:99–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97 std::fill( table_.begin(), table_.end(), -1 );
98 }
99 int find( const short * k, bool create = false ){
100 if (2*filled_ >= capacity_) grow();
101 // Get the hash value
102 size_t h = hash( k ) % capacity_;
103 // Find the element with he right key, using linear probing
104 while(1){
105 int e = table_[h];
106 if (e==-1){
107 if (create){
108 // Insert a new key and return the new id
109 for( size_t i=0; i<key_size_; i++ )
110 keys_[ filled_*key_size_+i ] = k[i];
111 return table_[h] = filled_++;
112 }
113 else
114 return -1;
115 }
116 // Check if the current key is The One
117 bool good = true;
118 for( size_t i=0; i<key_size_ && good; i++ )
119 if (keys_[ e*key_size_+i ] != k[i])
120 good = false;
121 if (good)
122 return e;
123 // Continue searching
124 h++;
125 if (h==capacity_) h = 0;
126 }
127 }
128 const short * getKey( int i ) const{
129 return &keys_[i*key_size_];
130 }

Callers 1

initMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected