?? tvutil.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: util.C,v 1.4 1996/04/18 21:50:24 kilin Exp kilin $ #include <stdlib.h>#include <iostream.h>#include <assert.h>#include "TVdefine.h"int sgn(float d1){ if (d1 > 0) return(1); if (d1 < 0) return(-1); return(0);}/* get the value of the Hadmnard matrix *//* row, column start at 0 */int hadamard1(int n, int row, int column){ int quad; if (n == 1) { if ((row > 1) || (column > 1)) { cout << "Error in hadamard"; assert(0); } else { if ((row == 1) && (column == 1)) return(-1); else return(1); } } else { quad = 2 * (row >= (n / 2) ) + (column >= (n / 2)); switch (quad){ case 0 : return(hadamard1(n/2, row, column)); break; case 1 : return(hadamard1(n/2, row, column - (n/2))); break; case 2 : return(hadamard1(n/2, row - (n/2), column)); break; case 3 : return(-hadamard1(n/2, row - (n/2), column - (n/2))); break; } } return 0;}int hadamard2(int n, int row, int column){ int quad; int n1, r1, c1; int ressig; n1 = n; r1 = row; c1 = column; ressig = 1; while (n1 > 2) { quad = 2 * (r1 >= (n1 / 2) ) + (c1 >= (n1 / 2)); switch (quad){ case 0 : break; case 1 : c1 = c1 - (n1/2); break; case 2 : r1 = r1 - (n1/2); break; case 3 : r1 = r1 - (n1/2); c1 = c1 - (n1/2); ressig = -ressig; break; } n1 = n1/2; } if ((r1 > 1) || (c1 > 1)) { printf("Ooooooops!\n"); } else { if ((r1 == 1) && (c1 == 1)) return(-ressig); else return(ressig); } return 0;}int hadamard(int n, int row, int column){ int pof2 = 1, i; for (i = 0; i < n; i++) pof2 = pof2 * 2; return(hadamard2(pof2, row, column));}/* return the corresponding entry in the smallest hadamard matrix with at leastminsize rows */int hadamard_minsize(int minsize, int row, int column){ int pof2 = 1, i; for (pof2 = 1; pof2 < minsize; pof2 = pof2 * 2) ; return(hadamard2(pof2, row, column));}/* get the logrithaithm */int logplusone(int n){ int sol = 0; while (n > 0) { n = n / 2; sol++; } return(sol);}/*// for hilbert curve calculationvoid inleave(char xcoor[], char ycoor[], char bitstr[]){ int xnum,ynum,ptr; xnum = strlen(xcoor); ynum = strlen(ycoor); if (xnum >= ynum) ptr = 2 * xnum; else ptr = 2 * ynum; bitstr[ptr--] = '\0'; while ((xnum != 0) && (ynum != 0)) { bitstr[ptr--] = ycoor[--ynum]; bitstr[ptr--] = xcoor[--xnum]; } if (xnum != 0) { while (xnum != 0) { bitstr[ptr--] = '0'; bitstr[ptr--] = xcoor[--xnum]; } } else if (ynum != 0) { while (ynum != 0) { bitstr[ptr--] = ycoor[--ynum]; bitstr[ptr--] = '0'; } }}*///*******************************************************************/// CONVERT : Takes a binary number, divides it into 2-bit */// strings, and assigns a decimal value to each string. */// '00' gets 0; '01' gets 1; '10' gets 3, and '11' gets 2. *///*******************************************************************//*void convert(char bitstr[], int string[] ,int count){ int n,i; n=0; i=0; while (i < count) { if (bitstr[n++] == '0') { if (bitstr[n] == '0') string[i++] = 0; else if (bitstr[n] == '1') string[i++] = 1; } else // the first number is one { if (bitstr[n] == '0') string[i++] = 3; else if (bitstr[n] == '1') string[i++] = 2; } n = n + 1; }}*///*******************************************************************/// SWITCHES : Switches numbers to correspond with the rotation */// of Hilbert's curve. *///*******************************************************************//*void switches(int string[], int count){ int i,j; for (i=0;i<count;i++) { if (string[i] == 0) { for (j=i+1;j<count;j++) { if (string[j] == 1) string[j] = 3; else if (string[j] == 3) string[j] = 1; } } else if (string[i] == 3) { for (j=i+1;j<count;j++) { if (string[j] == 0) string[j] = 2; else if (string[j] == 2) string[j] = 0; } } } }*///*******************************************************************/// COMPUTE : Computes the zvalue, given an array of manipulated */// numbers from SWITCHES. *///*******************************************************************//*int compute(int string[], int count){ int i,n; int zvalue; n=4; zvalue = string[count-1]; for (i=count-2; i>=0; i--) { zvalue = zvalue + (string[i] * n); n = n * 4; } return(zvalue);}*///*******************************************************************/// ZCOMP : Introduction procedure to calculate the zvalue of */// the Hilbert curve. *///*******************************************************************//*int zcomp(char xcoor[], char ycoor[]){ char bitstr[40]; int count; int string[20]; int zvalue; inleave(xcoor,ycoor,bitstr);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -