Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis12/src/include/Diderot/dyn-seq.h
ViewVC logotype

Annotation of /branches/vis12/src/include/Diderot/dyn-seq.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1691 - (view) (download) (as text)

1 : jhr 1691 /*! \file dyn-seq.h
2 :     *
3 :     * \author John Reppy
4 :     */
5 :    
6 :     /*
7 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
8 :     * All rights reserved.
9 :     */
10 :    
11 :     #ifndef _DIDEROT_DYN_SEQ_H_
12 :     #define _DIDEROT_DYN_SEQ_H_
13 :    
14 :     typedef struct {
15 :     unsigned int base;
16 :     size_t nElems;
17 :     size_t size;
18 :     void *data;
19 :     } Diderot_DynSeq_t;
20 :    
21 :     #define DYNSEQ_SUB(ty, seq, i) (*((ty *)Diderot_DynSeqAddr(sizeof(ty), seq, i)))
22 :     #define DYNSEQ_MK(ty, n, data) Diderot_DynSeqMk(sizeof(ty), n, data)
23 :    
24 :     inline Diderot_DynSeq_t *Diderot_DynSeqAlloc (size_t elemSz, int initialSz)
25 :     {
26 :     Diderot_DynSeq_t *seq = NEW(Diderot_DynSeq_t);
27 :     seq->base = 0;
28 :     seq->nElems = initialSz;
29 :     seq->size = initialSz; // FIXME: allow some padding
30 :     seq->data = CheckedAlloc (elemSz * seq->size);
31 :     return seq;
32 :     }
33 :    
34 :     inline Diderot_DynSeq_t *Diderot_DynSeqMk (size_t elemSz, int nElems, void *elems)
35 :     {
36 :     Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems);
37 :     unsigned char *p = (unsigned char *)seq->data;
38 :     unsigned char *q = (unsigned char *)elems;
39 :     for (int i = 0; i < nElems; i++) {
40 :     memcpy(p, q, elemSz);
41 :     p += elemSz;
42 :     q += elemSz;
43 :     }
44 :     return seq;
45 :     }
46 :    
47 :     inline void *Diderot_DynSeqAddr (size_t elemSz, Diderot_DynSeq_t *seq, int i)
48 :     {
49 :     i = (seq->base + i) % seq->size;
50 :     return ((char *)(seq->data) + elemSz * i);
51 :     }
52 :    
53 :     Diderot_DynSeq_t *Diderot_DynSeqAppend (size_t elemSz, Diderot_DynSeq_t *, void *);
54 :     Diderot_DynSeq_t *Diderot_DynSeqPrepend (size_t elemSz, void *, Diderot_DynSeq_t *);
55 :     Diderot_DynSeq_t *Diderot_DynSeqConcat (size_t elemSz, Diderot_DynSeq_t *, Diderot_DynSeq_t *);
56 :    
57 :     #endif /* !_DIDEROT_DYN_SEQ_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0