?? tvelement.c
字號:
/* COPYRIGHT NOTICE This material was developed by Christos Faloutsos and King-Ip Linat the University of Maryland, College Park, Department of Computer Science.Permission is granted to copy this software, to redistribute iton a nonprofit basis, and to use it for any purpose, subject tothe following restrictions and understandings. 1. Any copy made of this software must include this copyright noticein full. 2. All materials developed as a consequence of the use of thissoftware shall duly acknowledge such use, in accordance with the usualstandards of acknowledging credit in academic research. 3. The authors have made no warranty or representation that theoperation of this software will be error-free or suitable for anyapplication, and they are under under no obligation to provide anyservices, by way of maintenance, update, or otherwise. The softwareis an experimental prototype offered on an as-is basis. 4. Redistribution for profit requires the express, written permissionof the authors. */// Author : $Author$// Date : $Date$// Id : $Id$// $Id: element.C,v 1.2 1996/04/18 21:50:24 kilin Exp kilin $ #include <stdlib.h>#include <iostream.h>#include <assert.h>#include <fstream.h>#include <math.h>#include "TVdefine.h"#include "TVconstants.h"#include "TVvector.h"#include "TVelement.h"#include "TVutil.h"void _copy(char *source, char *dest, int bytes){ for (int i = 0; i < bytes; i++) dest[i] = source[i];}Leaf_Element::Leaf_Element(){ bytearray = NULL; noofbytes = 0;}Leaf_Element::Leaf_Element(char *barray, int bytes){ bytearray = new char[bytes]; noofbytes = bytes; _copy(barray, bytearray, bytes);}Leaf_Element::Leaf_Element(const Leaf_Element& ele){ noofbytes = ele.noofbytes; bytearray = new char[noofbytes]; _copy(ele.bytearray, bytearray, noofbytes); vec = ele.vec;}Leaf_Element::~Leaf_Element(){ if (bytearray) delete [] bytearray; bytearray = NULL;}Leaf_Element& Leaf_Element::operator=(const Leaf_Element& ele){ if (noofbytes != ele.noofbytes) { if (bytearray) delete [] bytearray; bytearray = NULL; noofbytes = ele.noofbytes; bytearray = new char[noofbytes]; } _copy(ele.bytearray, bytearray, noofbytes); vec = ele.vec; return *this;}int Leaf_Element::Size() const{ return vec.Size() + noofbytes + sizeof(int);}int Leaf_Element::ExpectedSize(int dim) const{ return vec.ExpectedSize(dim) + noofbytes + sizeof(int);}int Leaf_Element::BytearraySize() const{ return noofbytes;}TVector Leaf_Element::GetTVector(){ return vec;}Leaf_Element& Leaf_Element::DropDim(int dimtodrop){ if (dimtodrop > 0) vec = vec.ProjectFront(vec.GetDim() - dimtodrop); return *this;}TVector Leaf_Element::GetTVector(int dim, VCOM_TYPE (*gfeat)(int, char*), int store){ if (dim <= vec.GetDim()) return (dim ? vec.ProjectFront(dim) : vec); else { TVector vnew = GenNewTVector(dim - vec.GetDim(), gfeat); if (store) { vec <<= vnew; return vec; } else return (vec << vnew); }}// Get the compno-th feature // And add all the feature values to the feature vectorVCOM_TYPE Leaf_Element::GetFeature(int compno, VCOM_TYPE (*gfeat)(int, char*), int store){ assert(compno > 0); int vdim = vec.GetDim(); if (vdim >= compno) return vec[compno - 1]; // suppose a request of the 5th feature is made, // but only the first 2 features have been stored, // we will extract the 3rd-5th features. TVector vnew = GenNewTVector(compno - vdim, gfeat); VCOM_TYPE newcompo = vnew[compno - vdim - 1]; if (store) vec <<= vnew; return newcompo;}// Get the compno-th feature TVector Leaf_Element::GenNewTVector(int noofnewfeature, VCOM_TYPE (*gfeat)(int, char*)){ TVector vnew(noofnewfeature); int vdim = vec.GetDim(); for (int i = 1; i <= noofnewfeature; i++) vnew[i - 1] = gfeat(i + vdim, bytearray); return vnew;}// Check equality, byte-wise compareint Leaf_Element::equal(const Leaf_Element& le, int (*eq)(char *, int, char *, int)){ return eq(bytearray, noofbytes, le.bytearray, le.noofbytes);}// return the byte arraychar* Leaf_Element::operator()(){ char *result = new char[noofbytes]; for (int i = 0; i < noofbytes; i++) result[i] = bytearray[i]; return result;}// return distance between two elementsfloat Leaf_Element::Distance(const Leaf_Element& le, float (*dist)(char *, int, char *, int)){ return dist(bytearray, noofbytes, le.bytearray, le.noofbytes);}/*Leaf_Element& Leaf_Element::PreCompute(int compcount, VCOM_TYPE (*gfeat)(int, char*)){ assert(compcount > 0); // suppose a request of the 5th feature is made, // but only the first 2 features have been stored, // we will extract the 3rd-5th features. vec <<= GenNewTVector(compcount, gfeat); return *this;}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -