From aa4b17ac022b0f163e39d964213349b429275172 Mon Sep 17 00:00:00 2001 From: kishoramballi Date: Thu, 8 Oct 2009 06:08:31 +0000 Subject: [PATCH] First version. --- include/HeapAllocator.h | 108 ++++++++++++++++ include/OrderByTree.h | 85 +++++++++++++ include/OrderTableImpl.h | 116 ++++++++++++++++++ include/timecsql.h | 312 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 621 insertions(+) create mode 100644 include/HeapAllocator.h create mode 100644 include/OrderByTree.h create mode 100644 include/OrderTableImpl.h create mode 100644 include/timecsql.h diff --git a/include/HeapAllocator.h b/include/HeapAllocator.h new file mode 100644 index 00000000..b4d9d163 --- /dev/null +++ b/include/HeapAllocator.h @@ -0,0 +1,108 @@ +/*************************************************************************** + * * + * Copyright (C) Lakshya Solutions Ltd. All rights reserved. * + * * + ***************************************************************************/ + +#ifndef HEAP_ALLOCATOR +#define HEAP_ALLOCATOR +#include +#include +#define PAGEINFOSIZE 4 +#define BLOCKINFOSIZE 4 + +class VarHeapAllocator +{ + void *top; + void *last; + void *offset; + int pageSize; + int usedBytes; + int mode; + int newAllocateCounter; + int reAllocateCounter; + int pageCounter; + int deallocateCounter; + int isInitialized; + + void initializeInfo(void *ptr); + void initSize(int size); + + public: + VarHeapAllocator() + { + top = offset = NULL; + mode = 0; + isInitialized = 0; + pageCounter=0; + newAllocateCounter=0; + deallocateCounter=0; + reAllocateCounter=0; + } + void init(int size, int pMode =0); + void * allocate(int size); + void deallocate(void *); + void destroy(); + void print(); + void itirate(); +}; +class FixedHeapAllocator +{ + int blockSize; + int usedBytes; + int pageSize; + int allocateSize; + int isInitialized; + int newAllocateCounter; + int reAllocateCounter; + int pageCounter; + int deallocateCounter; + + void *top; + void *offset; + void initializeInfo(void *ptr); + + public: + FixedHeapAllocator() + { + top = offset = NULL; + isInitialized = 0; + pageCounter=0; + newAllocateCounter=0; + deallocateCounter=0; + reAllocateCounter=0; + } + void init(int pSize,int allocSize); + void *allocate(); + void deAllocate(void *ptr); + void destroy(); +}; +class HashMapNode +{ + public: + void *elem; + HashMapNode *next; + HashMapNode() { elem = NULL; next = NULL; } + void print() { printf("elem:%x next %x\n", elem, next); } +}; +class HashMap +{ + void **bucket; + int keySize; + int bucketSize; + bool optGrpIntNoNull; + public: + HashMap(){ keySize = 0; bucketSize = 1009; + bucket = (void**) ::malloc(bucketSize * sizeof(void*)); + memset(bucket, 0, bucketSize * sizeof(void*)); + optGrpIntNoNull = false; + } + ~HashMap() { ::free(bucket); } + void setKeySize(int size) { keySize = size; } + void setGrpIntNoNull(){ optGrpIntNoNull = true; } + DbRetVal insert(void *elem); + void* find(void *elem); + void removeAll(); +}; + +#endif diff --git a/include/OrderByTree.h b/include/OrderByTree.h new file mode 100644 index 00000000..442c6276 --- /dev/null +++ b/include/OrderByTree.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2007 by www.databasecache.com * + * Contact: praba_tuty@databasecache.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + ***************************************************************************/ +#ifndef ORDERBYTREE_H +#define ORDERBYTREE_H +#include +#include +#include +#include + +class OrderByFldDef +{ + public: + char fldName[IDENTIFIER_LENGTH]; + DataType type; + int length; + void *bindBuf; + bool isDesc; + bool alreadyBinded; + bool isNull; + int fldPos; + OrderByFldDef() + { + strcpy(fldName, ""); + type=typeUnknown; + length=0; + bindBuf=NULL; + isDesc= false; + alreadyBinded=false; + isNull = false; + fldPos=0; + } +}; + +enum OrderByType +{ + Asc=0, + Desc, + UnKnown, +}; +class OrderByTree +{ + OrderByType type; + int keySize; + bool isDistinct; + List dataNode; + List orderByList; + bool fullOrderBy; + HashMap projMap; //used in distinct projection + + public: + OrderByTree(){ isDistinct =false; fullOrderBy = false; keySize=0; type = UnKnown; dataNode.reset();} + DbRetVal insertDataNode(void *data); + bool find(void *data); + + //Used for float type field and individual order by clause + void insertSpecialCaseDataNode(void *data); + + void setKeySize(int size){ keySize = size; projMap.setKeySize(size);} + int getKeySize(){return keySize;} + void setDistinct(bool dist){ isDistinct = dist;} + bool getDistinct(){return isDistinct;} + void setOrderByType(OrderByType oType){ type = oType;} + OrderByType getOrderByType(){ return type; } + int compare(void *element1,void *element2,int size); + ListIterator getListIterator(); + void setOrderByList(List oList) { orderByList = oList; } + void setFullOrderBy() {fullOrderBy = true; } + void setOrdIntNoNull() { projMap.setGrpIntNoNull(); } + void removeAll(); +}; + +#endif diff --git a/include/OrderTableImpl.h b/include/OrderTableImpl.h new file mode 100644 index 00000000..94048699 --- /dev/null +++ b/include/OrderTableImpl.h @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (C) 2007 by www.databasecache.com * + * Contact: praba_tuty@databasecache.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + ***************************************************************************/ +#ifndef ORDERTABLE_IMPL_H +#define ORDERTABLE_IMPL_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class OrderTableImpl:public Table +{ + private: + char tblName_[IDENTIFIER_LENGTH]; + void *curTuple; //holds the current tuple ptr. moved during fetch() calls + List fldProjList; + List fldOrderByList; + Table *tableHdl; + List sortList; //change this list to some other data structure + ListIterator sortIter; + OrderByTree sortTree; + long long nullValues; + int orderBySize; + int projSize; + char *orderBuffer; + void *orderBindBuf; + bool isPlanCreated; + + DbRetVal copyValuesToBindBuffer(void *tuple); + void setNullableForProj(); + public: + OrderTableImpl(); + virtual ~OrderTableImpl(); + DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info) + { return tableHdl->getFieldInfo(fieldName, info); } + void setTable(Table *impl){ tableHdl = impl;} + Table* getTableHdl(){ return tableHdl; } + DbRetVal closeScan(); + void *getBindFldAddr(const char *name); + DbRetVal bindFld(const char *name, void *val); + void setProjList(List bindFldList) { fldProjList = bindFldList; } + DbRetVal setOrderBy(const char *name, bool isDesc=false); + DbRetVal setOrderByList(List orderList); + void setDistinct() { sortTree.setDistinct(true); } + OrderByType getOrderType(); + void checkAndSetSortAlgorithm(); + DbRetVal markFldNull(const char *name){ return ErrBadCall;} + DbRetVal markFldNull(int colpos){ return ErrBadCall;} + bool isFldNull(const char *name); + bool isFldNull(int colpos); + void clearFldNull(const char *name){} + void clearFldNull(int colpos){} + DbRetVal compact(){ return ErrBadCall;} + int getFldPos(char *name){ return 0;} + void resetNullinfo(){} + DbRetVal insertTuple() { return ErrBadCall; } + DbRetVal updateTuple() { return ErrBadCall; } + DbRetVal deleteTuple() { return ErrBadCall; } + int deleteWhere() { return ErrBadCall; } + int truncate() { return ErrBadCall; } + long spaceUsed() { return 0; } + int pagesUsed() { return 0; } + DbRetVal lock(bool shared) { return ErrBadCall; } + DbRetVal unlock(){ return ErrBadCall; } + DbRetVal setUndoLogging(bool flag) { return ErrBadCall; } + void printSQLIndexString(FILE *fp, int fd){ }; + void printSQLForeignString(){} + char* getName() { return tableHdl->getName(); } + List getFieldNameList(){ List dummyList; return dummyList;} + DbRetVal execute(); + DbRetVal insert(); + DbRetVal insertDistinct(); + void* fetch(); + void* fetch(DbRetVal &rv); + void* fetchNoBind(); + void* fetchNoBind(DbRetVal &rv); + DbRetVal close(); + long numTuples(); + void printInfo(); + bool pushPredicate(Predicate *pred) + { printf("Wrong call\n"); return false; } + void setPredicate(Predicate *pred) + { printf("Wrong call\n"); } + bool isTableInvolved(char *tableName) + { printf("Wrong call\n"); return false; } + void printPlan(int space); + DbRetVal optimize() + { printf("Wrong call\n"); return OK; } + bool isFKTable(){return false;} + ScanType getScanType(){ return unknownScan;} + bool hasIndex(char *fName){ return false;} + void setCondition(Condition *) {} + int computeOrderBySize(); +}; + +#endif diff --git a/include/timecsql.h b/include/timecsql.h new file mode 100644 index 00000000..c49f8eff --- /dev/null +++ b/include/timecsql.h @@ -0,0 +1,312 @@ +// COPY of time.h in solaris machine +// This copied to avoid compiler error +// "Multiple inclusion of std::tm" +#ifndef _CSQLTIME_H +#define _CSQLTIME_H + +#pragma ident "@(#)time.h 1.39 99/08/10 SMI" /* SVr4.0 1.18 */ + +#include +#include +#include + +/* + * Allow global visibility for symbols defined in + * C++ "std" namespace in . + */ +#if __cplusplus >= 199711L +using std::size_t; +using std::clock_t; +using std::time_t; +//using std::tm; +using std::asctime; +using std::clock; +using std::ctime; +using std::difftime; +using std::gmtime; +using std::localtime; +using std::mktime; +using std::time; +using std::strftime; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _CLOCKID_T +#define _CLOCKID_T +typedef int clockid_t; +#endif + +#ifndef _TIMER_T +#define _TIMER_T +typedef int timer_t; +#endif + +#if defined(__STDC__) + +#if defined(__EXTENSIONS__) || defined(_REENTRANT) || \ + (_POSIX_C_SOURCE - 0 >= 199506L) +extern struct tm *gmtime_r(const time_t *, struct tm *); +extern struct tm *localtime_r(const time_t *, struct tm *); +#endif /* defined(__EXTENSIONS__) || defined(_REENTRANT) .. */ + +#if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ + (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 >= 4) || \ + defined(__EXTENSIONS__) +extern char *strptime(const char *, const char *, struct tm *); + +#ifdef _STRPTIME_DONTZERO +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname strptime __strptime_dontzero +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *__strptime_dontzero(const char *, const char *, struct tm *); +#define strptime __strptime_dontzero +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* _STRPTIME_DONTZERO */ + +#endif /* (__STDC__ == 0 && !defined(_POSIX_C_SOURCE)... */ + +#if defined(__EXTENSIONS__) || ((__STDC__ - 0 == 0) && \ + !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ + (_POSIX_C_SOURCE > 2) +#include + +/* + * Neither X/Open nor POSIX allow the inclusion of for the + * definition of the sigevent structure. Both require the inclusion + * of and when using the timer_create() function. + * However, X/Open also specifies that the sigevent structure be defined + * in as described in the header . This prevents + * compiler warnings for applications that only include and not + * also . The sigval union and the sigevent structure is + * therefore defined both here and in which gets included + * via inclusion of . + */ +#ifndef _SIGVAL +#define _SIGVAL +union sigval { + int sival_int; /* integer value */ + void *sival_ptr; /* pointer value */ +}; +#endif /* _SIGVAL */ + +#ifndef _SIGEVENT +#define _SIGEVENT +struct sigevent { + int sigev_notify; /* notification mode */ + int sigev_signo; /* signal number */ + union sigval sigev_value; /* signal value */ + void (*sigev_notify_function)(union sigval); + pthread_attr_t *sigev_notify_attributes; + int __sigev_pad2; +}; +#endif /* _SIGEVENT */ + +extern int clock_getres(clockid_t, struct timespec *); +extern int clock_gettime(clockid_t, struct timespec *); +extern int clock_settime(clockid_t, const struct timespec *); +extern int timer_create(clockid_t, struct sigevent *, timer_t *); +extern int timer_delete(timer_t); +extern int timer_getoverrun(timer_t); +extern int timer_gettime(timer_t, struct itimerspec *); +extern int timer_settime(timer_t, int, const struct itimerspec *, + struct itimerspec *); +extern int nanosleep(const struct timespec *, struct timespec *); +#endif /* defined(__EXTENSIONS__) || ((__STDC__ - 0 == 0 && ... */ + +#if defined(__EXTENSIONS__) || __STDC__ == 0 || \ + defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) +extern void tzset(void); + +extern char *tzname[2]; + +#ifndef CLK_TCK +extern long _sysconf(int); /* System Private interface to sysconf() */ +#define CLK_TCK ((clock_t) _sysconf(3)) /* clock ticks per second */ + /* 3 is _SC_CLK_TCK */ +#endif + +#if defined(__EXTENSIONS__) || (__STDC__ == 0 && \ + !defined(_POSIX_C_SOURCE)) || defined(_XOPEN_SOURCE) +extern long timezone; +extern int daylight; +#endif + +#endif + +#if __STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) +extern int cftime(char *, char *, const time_t *); +extern int ascftime(char *, const char *, const struct tm *); +extern long altzone; +#endif + +#if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ + defined(_XPG4_2) || defined(__EXTENSIONS__) +extern struct tm *getdate(const char *); + +#ifdef _REENTRANT +#undef getdate_err +#define getdate_err *(int *)_getdate_err_addr() +extern int *_getdate_err_addr(void); +#else +extern int getdate_err; +#endif /* _REENTRANT */ +#endif /* __STDC__ == 0 && !defined(_POSIX_C_SOURCE) ... */ + +#else /* __STDC__ */ + +extern char *strptime(); +extern int cftime(), ascftime(); +extern void tzset(); + +#ifdef _STRPTIME_DONTZERO +#ifdef __PRAGMA_REDEFINE_EXTNAME +#pragma redefine_extname strptime __strptime_dontzero +#else /* __PRAGMA_REDEFINE_EXTNAME */ +extern char *__strptime_dontzero(); +#define strptime __strptime_dontzero +#endif /* __PRAGMA_REDEFINE_EXTNAME */ +#endif /* _STRPTIME_DONTZERO */ + + +#if defined(__EXTENSIONS__) || defined(_REENTRANT) || \ + (_POSIX_C_SOURCE - 0 >= 199506L) +extern struct tm *gmtime_r(); +extern struct tm *localtime_r(); +#endif /* defined(__EXTENSIONS__) || defined(_REENTRANT) .. */ + +extern long timezone, altzone; +extern int daylight; +extern char *tzname[2]; + +#if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ + defined(_XPG4_2) || defined(__EXTENSIONS__) +extern struct tm *getdate(); +#ifdef _REENTRANT +#undef getdate_err +#define getdate_err *(int *)_getdate_err_addr() +extern int *_getdate_err_addr(); +#else +extern int getdate_err; +#endif /* _REENTRANT */ +#endif /* __STDC__ == 0 && !defined(_POSIX_C_SOURCE) ... */ + + +#endif /* __STDC__ */ + +/* + * ctime_r() & asctime_r() prototypes are defined here. + */ + +/* + * Previous releases of Solaris, starting at 2.3, provided definitions of + * various functions as specified in POSIX.1c, Draft 6. For some of these + * functions, the final POSIX 1003.1c standard had a different number of + * arguments and return values. + * + * The following segment of this header provides support for the standard + * interfaces while supporting applications written under earlier + * releases. The application defines appropriate values of the feature + * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate + * whether it was written to expect the Draft 6 or standard versions of + * these interfaces, before including this header. This header then + * provides a mapping from the source version of the interface to an + * appropriate binary interface. Such mappings permit an application + * to be built from libraries and objects which have mixed expectations + * of the definitions of these functions. + * + * For applications using the Draft 6 definitions, the binary symbol is + * the same as the source symbol, and no explicit mapping is needed. For + * the standard interface, the function func() is mapped to the binary + * symbol _posix_func(). The preferred mechanism for the remapping is a + * compiler #pragma. If the compiler does not provide such a #pragma, the + * header file defines a static function func() which calls the + * _posix_func() version; this is required if the application needs to + * take the address of func(). + * + * NOTE: Support for the Draft 6 definitions is provided for compatibility + * only. New applications/libraries should use the standard definitions. + */ + +#if defined(__EXTENSIONS__) || defined(_REENTRANT) || \ + (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) + +#if defined(__STDC__) + +#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) + +#ifdef __PRAGMA_REDEFINE_EXTNAME +extern char *asctime_r(const struct tm *, char *); +extern char *ctime_r(const time_t *, char *); +#pragma redefine_extname ctime_r __posix_ctime_r +#pragma redefine_extname asctime_r __posix_asctime_r +#else /* __PRAGMA_REDEFINE_EXTNAME */ + +static char * +asctime_r(const struct tm *__tm, char *__buf) +{ + extern char *__posix_asctime_r(const struct tm *, char *); + return (__posix_asctime_r(__tm, __buf)); +} +static char * +ctime_r(const time_t *__time, char *__buf) +{ + extern char *__posix_ctime_r(const time_t *, char *); + return (__posix_ctime_r(__time, __buf)); +} +#endif /* __PRAGMA_REDEFINE_EXTNAME */ + +#else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ + +extern char *asctime_r(const struct tm *, char *, int); +extern char *ctime_r(const time_t *, char *, int); + +#endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ + +#else /* __STDC__ */ + +#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) + +#ifdef __PRAGMA_REDEFINE_EXTNAME +extern char *asctime_r(); +extern char *ctime_r(); +#pragma redefine_extname asctime_r __posix_asctime_r +#pragma redefine_extname ctime_r __posix_ctime_r +#else /* __PRAGMA_REDEFINE_EXTNAME */ + +static char * +asctime_r(__tm, __buf) + struct tm *__tm; + char *__buf; +{ + extern char *__posix_asctime_r(); + return (__posix_asctime_r(__tm, __buf)); +} +static char * +ctime_r(__time, __buf) + time_t *__time; + char *__buf; +{ + extern char *__posix_ctime_r(); + return (__posix_ctime_r(__time, __buf)); +} +#endif /* __PRAGMA_REDEFINE_EXTNAME */ + +#else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ + +extern char *asctime_r(); +extern char *ctime_r(); + +#endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ + +#endif /* __STDC__ */ + +#endif /* defined(__EXTENSIONS__) || (__STDC__ == 0 ... */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TIME_H */ -- 2.11.4.GIT