This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int* bsearch(int val, int* base, int nelems) | |
{ | |
if (base == NULL || nelems == 0) | |
return NULL; | |
int lo = 0; | |
int hi = nelems - 1; | |
for (;;) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int binarysearch(DataType t) | |
/* return (any) position | |
if t in sorted x[0..n-1] or | |
-1 if t is not present */ | |
{ | |
int l, u, m; | |
l = 0; | |
u = n-1; | |
while (l <= u) { | |
m = (l + u) / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overloading operator, to allow custom list of objects to be passed | |
// eg: object obj()[, , , ]; | |
struct list | |
{ | |
... | |
list& operator,(list l); | |
... | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sort(int* A, int n) | |
{ | |
for (int i = 0; i < n; ++i) | |
for (int j = i+1; j < n; ++j) | |
if (A[j] < A[i]) | |
{ | |
int tmp = A[i]; | |
A[i] = A[j]; | |
A[j] = tmp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sort2(int* A, int n) | |
{ | |
for (int i = 0; i < n; ++i) | |
{ | |
int min = i; | |
for (int j = i+1; j < n; ++j) | |
{ | |
if (A[j] < A[min]) | |
min = j; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Flags | |
{ | |
Flag1 = 0x1, | |
Flag2 = 0x2, | |
Flag3 = 0x4, | |
Flag4 = 0x8 | |
}; | |
Flags operator|(Flags a, Flags b) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with cl /O2 sorting.cpp winmm.lib | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <Windows.h> | |
void exch(int& a, int& b) | |
{ | |
int tmp = a; a = b; b = tmp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// One of many test.cpp I found. I think this one was for examining the generated assembly. | |
#include "xmmintrin.h" | |
#if 0 | |
struct Vec3 | |
{ | |
float x, y, z; | |
__forceinline Vec3() {}; | |
__forceinline Vec3(float X, float Y, float Z) : x(X), y(Y), z(Z) {}; | |
__forceinline Vec3 operator*(const Vec3& t) const { return Vec3(x*t.x, y*t.y, z*t.z); }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Yet another test. Also had a .obj along side. | |
#include <winsock2.h> | |
int | |
main() | |
{ | |
u_short x = 1; | |
x = htons(x); | |
return x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Another test. RGB->YCoCg conversion. Think I discovered a problem with negative | |
// values being returned on RGB->YCoCg->RGB. | |
#include <stdio.h> | |
struct IVect { int x, y, z; }; | |
/* | |
* [Y ] = [ 1/4 1/2 1/4][R] R, G, B = [0..255] => Y = [0..255], Co, Cg = [-128..127] | |
* [Co] [ 1/2 0 -1/2][G] | |
* [Cg] [-1/4 1/2 -1/4][B] |
OlderNewer