📄 data.h
字号:
virtual ObjHandle findNext(ObjHandle h) const; virtual ObjHandle findPrev(ObjHandle h) const; virtual Object * get(ObjHandle h) const; virtual uint getObjIdx(ObjHandle h) const; /* extends Container */ virtual void delAll(); virtual bool del(ObjHandle h); virtual ObjHandle insert(Object *obj); virtual Object * remove(ObjHandle h); /* extends List */ virtual void forceSetByIdx(int idx, Object *obj); virtual void insertAt(ObjHandle h, Object *obj); virtual bool moveTo(ObjHandle from, ObjHandle to); virtual bool set(ObjHandle h, Object *obj); virtual bool swap(ObjHandle h, ObjHandle i);};/** * BinaryTree's node structure */struct BinTreeNode { Object *key; BinTreeNode *left, *right; int unbalance;};/** * A simple binary tree */class BinaryTree: public Container {protected: bool own_objects; uint ecount; BinTreeNode *root; Comparator compare; BinTreeNode * allocNode() const; void cloneR(BinTreeNode *node); virtual void deleteNode(BinTreeNode *node) const; BinTreeNode * findNode(BinTreeNode *node, const Object *obj) const; BinTreeNode * findNodeG(BinTreeNode *node, const Object *obj) const; BinTreeNode * findNodeGE(BinTreeNode *node, const Object *obj) const; BinTreeNode * findNodeL(BinTreeNode *node, const Object *obj) const; BinTreeNode * findNodeLE(BinTreeNode *node, const Object *obj) const; BinTreeNode ** findNodePtr(BinTreeNode **nodeptr, const Object *obj) const; void freeAll(BinTreeNode *n); void freeObj(Object *obj) const; BinTreeNode * getLeftmost(BinTreeNode *node) const; BinTreeNode * getRightmost(BinTreeNode *node) const; BinTreeNode ** getLeftmostPtr(BinTreeNode **nodeptr) const; BinTreeNode ** getRightmostPtr(BinTreeNode **nodeptr) const; ObjHandle findByIdxR(BinTreeNode *n, int &i) const; ObjHandle insertR(BinTreeNode *&node, Object *obj); void loadR(ObjectStream &s, BinTreeNode **n, int l, int r); void storeR(ObjectStream &s, BinTreeNode *n) const; virtual void setNodeIdentity(BinTreeNode *node, BinTreeNode *newident); inline bool validHandle(ObjHandle h) const { return (h != invObjHandle); } inline BinTreeNode * handleToNative(ObjHandle h) const { return (BinTreeNode*)h; } inline ObjHandle nativeToHandle(BinTreeNode *n) const { return (ObjHandle*)n; }public: BinaryTree(BuildCtorArg&a): Container(a) {}; BinaryTree(bool own_objects, Comparator comparator = autoCompare); virtual ~BinaryTree(); /* extends Object */ virtual BinaryTree * clone() const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const; /* extends Enumerator */ virtual void delAll(); virtual uint count() const; virtual int compareObjects(const Object *a, const Object *b) const; virtual ObjHandle find(const Object *obj) const; virtual ObjHandle findG(const Object *obj) const; virtual ObjHandle findGE(const Object *obj) const; virtual ObjHandle findL(const Object *obj) const; virtual ObjHandle findLE(const Object *obj) const; virtual ObjHandle findByIdx(int i) const; virtual ObjHandle findFirst() const; virtual ObjHandle findLast() const; virtual ObjHandle findNext(ObjHandle h) const; virtual ObjHandle findPrev(ObjHandle h) const; virtual Object * get(ObjHandle h) const; virtual uint getObjIdx(ObjHandle h) const; /* extends Container */ virtual bool del(ObjHandle h); virtual ObjHandle insert(Object *obj); virtual Object * remove(ObjHandle h);};/** * A height-balanced binary tree (AVL) */class AVLTree: public BinaryTree {private: void cloneR(BinTreeNode *node); BinTreeNode * removeR(Object *key, BinTreeNode *&root, int &change, int cmp); int loadR(ObjectStream &s, BinTreeNode *&n, int l, int r);public: AVLTree(BuildCtorArg&a): BinaryTree(a) {}; AVLTree(bool own_objects, Comparator comparator = autoCompare); void debugOut(); bool expensiveCheck() const; /* extends Object */ virtual AVLTree * clone() const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; /* extends Container */ virtual ObjHandle insert(Object *obj); virtual Object * remove(ObjHandle h);};/** * MRU Cache's node structure */struct MRUCacheNode: public BinTreeNode { MRUCacheNode *moreRU, *lessRU;};/** * A most-recently-used (MRU) cache */class MRUCache: public AVLTree {private: MRUCacheNode * mostRU; MRUCacheNode * leastRU; virtual MRUCacheNode * allocNode() const; void checkList() const; virtual void deleteNode(BinTreeNode *node) const; inline MRUCacheNode * handleToNative(ObjHandle h) const { return (MRUCacheNode*)h; } inline ObjHandle nativeToHandle(MRUCacheNode *n) const { return (ObjHandle)n; } virtual void setNodeIdentity(BinTreeNode *node, BinTreeNode *newident);public: MRUCache(bool own_objects, Comparator comparator = autoCompare); /* extends Object */ virtual MRUCache * clone() const; virtual void store(ObjectStream &s) const; /* extends Container */ virtual ObjHandle insert(Object *obj); virtual Object * remove(ObjHandle h); /* extends AVLTree */ virtual void delAll(); /* new */ void propagate(ObjHandle h); ObjHandle getLRU();};/** * A finite set */class Set: public AVLTree {public: Set(BuildCtorArg&a):AVLTree(a) {}; Set(bool own_objects); /* new */ void intersectWith(Set *b); void unionWith(Set *b); inline bool operator &(Object *obj) const { return contains(obj); } virtual ObjectID getObjectID() const;};/* * IntSet */class IntSet: public Object {protected: uint mMaxSetSize; // in bits uint mSetSize; // in bits byte *mSet; /* new */ inline uint idx2ByteOfs(uint i) const; inline uint idx2BitMask(uint i) const; void makeAccessible(uint i); inline bool isAccessible(uint i) const;public: IntSet(uint aMaxSetSize); virtual ~IntSet(); /* extends Object */ virtual IntSet *clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; /* new */ void assign(const IntSet &from); bool contains(uint i) const; void del(uint i); void delAll(); bool findFirst(uint &i, bool set) const; bool findNext(uint &i, bool set) const; bool findPrev(uint &i, bool set) const; void insert(uint i);};/** * Maintains a key-value pair for easy inserting objects with "simple" keys * into Containers. * Key and Value will be <code>delete</code>d in the destructor. */class KeyValue: public Object {public: Object *mKey; Object *mValue; KeyValue(BuildCtorArg&a): Object(a) {}; KeyValue(Object *aKey, Object *aValue): mKey(aKey), mValue(aValue) {}; virtual ~KeyValue(); virtual KeyValue * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};/** * A signed Integer */class SInt: public Object {public: signed int value; SInt(BuildCtorArg&a): Object(a) {}; SInt(signed int i): value(i) {}; /* extends Object */ virtual SInt * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};typedef SInt Integer;/** * A signed Integer (64-bit) */class SInt64: public Object {public: sint64 value; SInt64(BuildCtorArg&a): Object(a) {}; SInt64(sint64 i): value(i) {}; /* extends Object */ virtual SInt64 * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};/** * An unsigned Integer */class UInt: public Object {public: unsigned int value; UInt(BuildCtorArg&a): Object(a) {}; UInt(unsigned int i): value(i) {}; /* extends Object */ virtual UInt * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};/** * An unsigned Integer (64-bit) */class UInt64: public Object {public: uint64 value; UInt64(BuildCtorArg&a): Object(a) {}; UInt64(uint64 i): value(i) {}; /* extends Object */ virtual UInt64 * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};/** * A floating-point number (FIXME: no portable storage yet) */class Float: public Object {public: double value; Float(BuildCtorArg&a): Object(a) {}; Float(double d): value(d) {}; /* extends Object */ virtual Float * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const;// virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const;// virtual void store(ObjectStream &s) const;};/** * A pointer. Cannot be stored. */class Pointer: public Object {public: void *value; Pointer(void *p): value(p) {};};/** * A memory area. */class MemArea: public Object {private: bool duplicate;public: void *ptr; uint size; MemArea(BuildCtorArg&a): Object(a) {}; MemArea(const void *p, uint size, bool duplicate = false); ~MemArea(); /* extends Object */ virtual MemArea * clone() const; virtual int compareTo(const Object *obj) const; virtual int toString(char *buf, int buflen) const; virtual void load(ObjectStream &s); virtual ObjectID getObjectID() const; virtual void store(ObjectStream &s) const;};/* * sorter */bool quickSort(List &l);/* * char_set */#define CS_SETSIZE 256typedef struct char_set { unsigned char char_bits [((CS_SETSIZE) + 7) / 8];} char_set;#define CS_SET(n, p) ((p)->char_bits[(n) / 8] |= (1 << ((n) & 7)))#define CS_CLR(n, p) ((p)->char_bits[(n) / 8] &= ~(1 << ((n) & 7)))#define CS_ISSET(n, p) ((p)->char_bits[(n) / 8] & (1 << ((n) & 7)))#define CS_ZERO(p) memset ((void *)(p), 0, sizeof (*(p)))/* * */#define BITMAP(a0, a1, a2, a3, a4, a5, a6, a7) (((a0)<<0) | ((a1)<<1) | ((a2)<<2) | ((a3)<<3) | ((a4)<<4) | ((a5)<<5) | ((a6)<<6) | ((a7)<<7))#define BITBIT(bitmap, p) ((bitmap)>>(p)&1)/* * simple int hash */struct int_hash { int value; const char *desc;};const char *matchhash(int value, int_hash *hash_table);#include "stream.h" // load/store need ObjectStream/* * Module Init/Done */bool init_data();void done_data();#endif /* __DATA_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -