-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpq_delete.cpp
56 lines (50 loc) · 1.79 KB
/
pq_delete.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//==============================================================================
// Name : pq_delete.cpp
// Author : Andrea Tagliasacchi
// Version : 1.0
// Copyright : 2009 (c) Andrea Tagliasacchi
// Description : Frees the memory allocated by the priority queue
//
// May 22, 2009: Created
//==============================================================================
#include "MyHeap.h"
//------------------------------- MATLAB -------------------------------------//
#ifdef MATLAB_MEX_FILE
#ifdef _CHAR16T
#define CHAR16_T
#endif
#include "mex.h"
#define toSysout(...) printf(__VA_ARGS__)
#define exit_with_error(...) \
do { \
fprintf(stdout, "Error: "); \
fprintf(stdout, __VA_ARGS__ ); \
fprintf(stdout, "\n" ); \
exit(1); \
} while(0)
void retrieve_heap( const mxArray* matptr, MaxHeap<double>* & heap){
// retrieve pointer from the MX form
double* pointer0 = mxGetPr(matptr);
// check that I actually received something
if( pointer0 == NULL )
mexErrMsgTxt("vararg{1} must be a valid priority queue pointer\n");
// convert it to "long" datatype (good for addresses)
long pointer1 = (long) pointer0[0];
// convert it to "KDTree"
heap = (MaxHeap<double>*) pointer1;
// check that I actually received something
if( heap == NULL )
mexErrMsgTxt("vararg{1} must be a valid priority queue pointer\n");
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
if( nrhs!=1 )
mexErrMsgTxt("This function requires 3 arguments\n");
if( !mxIsNumeric(prhs[0]) )
mexErrMsgTxt("parameter 1 missing!\n");
// retrieve the heap
MaxHeap<double>* heap;
retrieve_heap( prhs[0], heap);
// delete the heap
heap -> ~MaxHeap<double>();
}
#endif