MCPcopy Create free account
hub / github.com/creatale/node-dv / newNode

Method newNode

deps/opencv/modules/core/src/matrix.cpp:4023–4066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4021}
4022
4023uchar* SparseMat::newNode(const int* idx, size_t hashval)
4024{
4025 const int HASH_MAX_FILL_FACTOR=3;
4026 assert(hdr);
4027 size_t hsize = hdr->hashtab.size();
4028 if( ++hdr->nodeCount > hsize*HASH_MAX_FILL_FACTOR )
4029 {
4030 resizeHashTab(std::max(hsize*2, (size_t)8));
4031 hsize = hdr->hashtab.size();
4032 }
4033
4034 if( !hdr->freeList )
4035 {
4036 size_t i, nsz = hdr->nodeSize, psize = hdr->pool.size(),
4037 newpsize = std::max(psize*2, 8*nsz);
4038 hdr->pool.resize(newpsize);
4039 uchar* pool = &hdr->pool[0];
4040 hdr->freeList = std::max(psize, nsz);
4041 for( i = hdr->freeList; i < newpsize - nsz; i += nsz )
4042 ((Node*)(pool + i))->next = i + nsz;
4043 ((Node*)(pool + i))->next = 0;
4044 }
4045 size_t nidx = hdr->freeList;
4046 Node* elem = (Node*)&hdr->pool[nidx];
4047 hdr->freeList = elem->next;
4048 elem->hashval = hashval;
4049 size_t hidx = hashval & (hsize - 1);
4050 elem->next = hdr->hashtab[hidx];
4051 hdr->hashtab[hidx] = nidx;
4052
4053 int i, d = hdr->dims;
4054 for( i = 0; i < d; i++ )
4055 elem->idx[i] = idx[i];
4056 size_t esz = elemSize();
4057 uchar* p = &value<uchar>(elem);
4058 if( esz == sizeof(float) )
4059 *((float*)p) = 0.f;
4060 else if( esz == sizeof(double) )
4061 *((double*)p) = 0.;
4062 else
4063 memset(p, 0, esz);
4064
4065 return p;
4066}
4067
4068
4069void SparseMat::removeNode(size_t hidx, size_t nidx, size_t previdx)

Callers 2

copyToMethod · 0.80
convertToMethod · 0.80

Calls 4

maxFunction · 0.70
elemSizeFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected