DLIST2.H
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2|* 1. <<< 双方向リスト・バッファ (DList2) >>>
3|***************************************************************************/
4|
5|#ifndef __DLIST2_H
6|#define __DLIST2_H
7|
8|/*----------------------------------------------------------------------
9|[Module Property]
10|name = DList2
11|title = 双方向リスト・バッファ
12|category = コンテナ
13|src = dlist2.c
14|depend = TypeX
15|priority =
16|accord =
17|----------------------------------------------------------------------*/
18|
19|#ifndef USES_PRIORITY_HEADER
20|/*[START_OF_PRIORITY_HEADER]*/
21|
22|#define USES_DLIST2
23|typedef struct _DList2 DList2;
24|typedef struct _DList2_Buf DList2_Buf;
25|
26|/*[END_OF_PRIORITY_HEADER]*/
27|#endif /* USES_PRIORITY_HEADER */
28|
29|
30|#ifndef USES_TYPEX
31|#ifndef _STDLIB
32|#error need _STDLIB or TYPEX
33|#endif
34|#endif
35|
36|#ifdef _STDLIB
37|#include <stdlib.h>
38|#endif
39|
40|
41|/*-----------------------------------------------------------------*/
42|/* 2. <<< Interface Area ---------------------------------------- >>> */
43|/*-----------------------------------------------------------------*/
44|
45|/**************************************************************************
46|* 3. <<< 双方向リスト(要素)[DList2] >>>
47|*【補足】
48|*・実際のデータを含む構造体の「先頭の」メンバに宣言するだけで、
49|* コンテナ DList2_Buf に登録することが出来るようになります。
50|* struct {
51|* DList2 list; // 先頭に付ける(extend)
52|* int member;
53|* : :
54|* };
55|***************************************************************************/
56|struct _DList2{
57| DList2* next;
58| DList2* prev;
59|};
60|DList2* DList2_move( DList2*, DList2* to );
61|void* DList2_linkArr( DList2* arr, size_t arr_sizeof, size_t elem_sizeof );
62|
63|
64|/**************************************************************************
65|* 4. <<< 双方向リストを使用したバッファ [DList2_Buf] >>>
66|*【補足】
67|*・集合を作成していくときに用います。
68|*・オーダー付きの集合として、集合の途中に要素を入れるのが高速なバッファです。
69|*・配列を使用したバッファは ArrX_Buf を用います。
70|*・malloc のようなメモリ管理は、ArrayU3 や CaStack を用います。
71|*【内部補足】
72|*・内部では、環状リスト構造になっています。
73|* DList2_Buf.use <--> DList2 <--> DList2 <--> DList2_Buf.use
74|* DList2_Buf.nouse <--> DList2 <--> DList2 <--> DList2_Buf.nouse
75|***************************************************************************/
76|struct _DList2_Buf{
77| DList2 use; /* 使用リスト */
78| DList2 nouse; /* 未使用リスト */
79|};
80|
81|void DList2_Buf_init( DList2_Buf*, DList2* arr, size_t arr_sizeof,
82| size_t elem_sizeof );
83|
84|DList2* DList2_Buf_alloc( DList2_Buf* );
85|DList2* DList2_Buf_allocIns( DList2_Buf*, DList2* at );
86|void DList2_Buf_free( DList2_Buf*, DList2* elem );
87|
88|DList2* DList2_Buf_getFirst( DList2_Buf* );
89|DList2* DList2_Buf_getOver( DList2_Buf* );
90|
91|void DList2_Buf_print( DList2_Buf* );
92|
93|
94|/*-----------------------------------------------------------------*/
95|/* 5. <<< Mapping Area ------------------------------------------ >>> */
96|/*-----------------------------------------------------------------*/
97|
98|/*-----------------------------------------------------------------*/
99|/* 6. <<< ◆双方向リストを用いたバッファ(DList2_Buf) >>> */
100|/*-----------------------------------------------------------------*/
101|
102|/**************************************************************************
103|* 7. <<< 構造体1つ分のバッファをアロケートする(末尾)[DList2_Buf_alloc()] >>>
104|*【補足】
105|*・配列ではないので、複数の構造体を一度にアロケートすることは出来ません。
106|***************************************************************************/
107|#define DList2_Buf_alloc( this ) \
108| (DList2_move( (this)->nouse.next, &(this)->use ))
109|
110|/**************************************************************************
111|* 8. <<< 構造体1つ分のバッファをアロケートする(挿入)[DList2_Buf_allocIns()] >>>
112|*【補足】
113|*・配列ではないので、複数の構造体を一度にアロケートすることは出来ません。
114|***************************************************************************/
115|#define DList2_Buf_allocIns( this, at ) \
116| (DList2_move( (this)->nouse.next, (DList2*)(at) ))
117|
118|/**************************************************************************
119|* 9. <<< 構造体1つ分のバッファをフリーする [DList2_Buf_free()] >>>
120|*【補足】
121|*・配列ではないので、複数の構造体を一度にフリーすることは出来ません。
122|***************************************************************************/
123|#define DList2_Buf_free( this, elem ) \
124| (DList2_move( (DList2*)(elem), (this)->nouse.next ))
125|
126|/**************************************************************************
127|* 10. <<< アロケートされている最初の要素のアドレスを返す [DList2_Buf_getFirst()] >>>
128|*【例】
129|* type* p = (type*)DList2_Buf_getFirst( this );
130|* type* p_over = (type*)DList2_Buf_getOver( this );
131|* for ( ; p != p_over; p = (type*)p->dlist.next ) {
132|* p->member = n;
133|* }
134|***************************************************************************/
135|#define DList2_Buf_getFirst( this ) \
136| ((this)->use.next)
137|
138|/**************************************************************************
139|* 11. <<< アロケートされている末尾の次の要素のアドレスを返す [DList2_Buf_getOver()] >>>
140|***************************************************************************/
141|#define DList2_Buf_getOver( this ) \
142| ((DList2*)&(this)->use)
143|
144|#endif /* __DLIST2_H */
145|
146|