• R/O
  • SSH
  • HTTPS

globalbase: Commit


Commit MetaInfo

Révision5989 (tree)
l'heure2019-12-04 23:24:38
Auteurjoshua

Message de Log

array queue

Change Summary

Modification

--- modules/tinyState/trunk/src/h/ts/c++/stdArrayQueue.h (nonexistent)
+++ modules/tinyState/trunk/src/h/ts/c++/stdArrayQueue.h (revision 5989)
@@ -0,0 +1,73 @@
1+
2+
3+
4+#ifndef ___stdArrayQueue_cpp_H___
5+#define ___stdArrayQueue_cpp_H___
6+
7+
8+template <class __TYPE>
9+class stdArrayQueue : public stdObject {
10+public:
11+ stdArrayQueue(int len) {
12+ REF_SET(a,(NEW stdArray<__TYPE,false>(len)));
13+ head = tail = 0;
14+ }
15+ ~stdArrayQueue() {
16+ REF_SET(a,0);
17+ }
18+ int length() {
19+ return a->length();
20+ }
21+ int count() {
22+ return _count;
23+ }
24+ void length(int len) {
25+ int i,j,ncount;
26+ n = NEW stdArray<__TYPE,false>(len);
27+ if ( count < len )
28+ ncount = _count();
29+ else ncount = len;
30+ j = 0;
31+ i = -ncount;
32+ for ( ; i < 0 ; i ++ , j ++ )
33+ n->ary[j] = get(i);
34+ REF_SET(a,n);
35+ tail = 0;
36+ head = ncount;
37+ _count = ncount;
38+ }
39+ __TYPE * ins() {
40+ __TYPE ret;
41+ _count ++;
42+ ret = &a->ary[head++];
43+ if ( head >= a->length() )
44+ head = 0;
45+ if ( head != tail ) {
46+ return ret;
47+ }
48+ del();
49+ return ret;
50+ }
51+ void del() {
52+ _count --;
53+ tail ++;
54+ if ( tail >= a->length() )
55+ tail = 0;
56+ }
57+ __TYPE * get(int pos=-1) {
58+ if ( pos >= 0 )
59+ return 0;
60+ if ( pos < -_count )
61+ return 0;
62+ pos = head + pos;
63+ for ( ; pos < 0 ; pos += a->length() );
64+ return a->ary[pos];
65+ }
66+protected:
67+ stdArray<__TYPE,false> * a;
68+ int head;
69+ int tail;
70+ int _count;
71+};
72+
73+#endif
Afficher sur ancien navigateur de dépôt.