?? data.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: data.C,v 1.4 1996/04/18 21:50:24 kilin Exp kilin $ #include <stdlib.h>#include <iostream.h>#include <fstream.h>#include "TVdefine.h"#include "data.h"int DataPoints::dim = DEFAULT_DATADIM;DataPoints::DataPoints(){ points = new int[dim];}DataPoints::DataPoints(char * ia){ points = new int[dim]; int *iarray = (int *)ia; key = iarray[0]; for (int i = 0; i < dim; i++) points[i] = iarray[i+1]; }DataPoints::~DataPoints(){ delete [] points;}int& DataPoints::operator[](int p){ return *(&points[p]);}char* DataPoints::operator()(){ int *arr = new int[dim + 1]; arr[0] = key; for (int i = 0; i < dim; i++) arr[i + 1] = points[i]; return (char *)arr;}int DataPoints::Size() const{ return (dim + 1) * sizeof(int);}int DataPoints::operator==(const DataPoints& dp) const{ int i = 0; for (; (i < dim) && (points[i] == dp.points[i]) ; i++) ; return (i == DataPoints::dim); }float DataPoints::Distance(const DataPoints& dp) { float res = 0.0; for (int i = 0; (i < dim) ; i++) res += abs(points[i] - dp.points[i]); return res; }istream& operator>>(istream& is, DataPoints& dp){ is >> dp.key; for (int i = 0; i < DataPoints::dim; i++) is >> dp.points[i]; return is;}/*// do not read in the keysistream& operator>>=(istream& is, DataPoints& dp){ for (int i = 0; i < DataPoints::dim; i++) is >> dp.points[i]; return is;}*/istream& operator>>=(istream& is, DataPoints& dp){ is.read(dp.points, DataPoints::dim * sizeof(int)); return is;}ostream& operator<<(ostream& os, DataPoints& dp){ os << "[" << dp.key << "] (" << dp.points[0]; for (int i = 1; i < DataPoints::dim; i++) os << ", " << dp.points[i]; os << ")"; return os;}ofstream& operator<(ofstream& os, DataPoints& dp){ os << dp.key; for (int i = 0; i < DataPoints::dim; i++) os << " " << dp.points[i]; os << " "; return os;}char *ReadData(ifstream& is, int& size){ DataPoints dp; is >> dp; size = dp.Size(); return dp(); }void WriteData(ofstream& of, char *iarray, int size){ DataPoints dp(iarray); of < dp;}void PrintData(ostream& of, char *iarray){ DataPoints dp(iarray); of << dp;}VCOM_TYPE GetFeature(int fno, char *iarray){ DataPoints dp(iarray); return dp[fno - 1];}int Equal(char* arr1, char* arr2){ DataPoints dp1(arr1); DataPoints dp2(arr2); return dp1 == dp2;}char *GetKey(char *arr1, int osize, int& size){ DataPoints dp1(arr1); size = sizeof(int); int *k = new int; *k = dp1.key; return (char *)k;}char *GetWholeThing(char *arr1, int osize, int& size){ size = osize; return arr1;}void PrintKey(ostream& of, char *iarray){ of << *((int *)iarray);}float Distance(char* arr1, char* arr2){ DataPoints dp1(arr1); DataPoints dp2(arr2); return dp1.Distance(dp2);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -