/* * * Copyright (c) 2008--2012 * Advanced Algorithm and Algorithm Engineering Group * National Engineering Laboratory for Information Security Technologies (NELIST) * Institute of Information Engineering, Chinese Academy of Sciences (IIE-CAS) * All rights reserved * * Written by: LIU YANBING (liuyanbing@iie.ac.cn) * Last modification: 2012-11-27 * * This code is the exclusive and proprietary property of NELIST and IIE-CAS. * Usage for direct or indirect commercial advantage is not allowed without * written permission from the authors. * */ #include "DirectIndex.h" #include #include using namespace std; //#define DEBUG_DIRECT_INDEX CDirectIndex::CDirectIndex() { m_keys=NULL; m_ptr=NULL; m_values=NULL; } CDirectIndex::~CDirectIndex() { if(m_keys!=NULL) delete [] m_keys; if(m_ptr!=NULL) delete [] m_ptr; if(m_values!=NULL) delete [] m_values; } /* closed interval: [a[i], b[i]] such that a[i]<=b[i] */ long long CDirectIndex::PreProcessing(const vector& a, const vector& b) { long long mem_bytes=0; unsigned long long count=0; for(unsigned int i=0; i2*a.size()) return -1; map M; for(unsigned int i=0; i::const_iterator it=M.begin(); for(unsigned int k=0; kfirst; m_ptr[k+1]=m_ptr[k]+it->second; } for(unsigned int i=0; i0; k--) { m_ptr[k]=m_ptr[k-1]; } m_ptr[0]=0; m_min_key=m_keys[0]; m_max_key=m_keys[M.size()-1]; for(unsigned int k=0; km_max_key) return 0; key-=m_min_key; unsigned int k=key>>m_theta; int l=m_L[k], h=(int)m_L[k+1]-1; if(h= size) { return n; } result[n++] = values[i]; } } return n; }