SCM Repository
View of /branches/vis12/src/include/Diderot/dyn-seq.h
Parent Directory
|
Revision Log
Revision 1733 -
(download)
(as text)
(annotate)
Tue Mar 13 14:09:15 2012 UTC (10 years, 3 months ago) by jhr
File size: 2402 byte(s)
Tue Mar 13 14:09:15 2012 UTC (10 years, 3 months ago) by jhr
File size: 2402 byte(s)
Preliminary library support for dynamic sequences.
/*! \file dyn-seq.h * * \author John Reppy */ /* * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. */ #ifndef _DIDEROT_DYN_SEQ_H_ #define _DIDEROT_DYN_SEQ_H_ typedef struct { unsigned int base; //!< data[base] is the first element in the sequence unsigned int nElems; //!< number of elements in the sequence unsigned int size; //!< size of data buffer in elements void *data; //!< pointer to underlying data buffer } Diderot_DynSeq_t; #define DYNSEQ_SUB(ty, seq, i) (*((ty *)Diderot_DynSeqAddr(sizeof(ty), seq, i))) #define DYNSEQ_MK(ty, n, data) Diderot_DynSeqMk(sizeof(ty), n, data) STATIC_INLINE unsigned int Diderot_DynSeqLength (Diderot_DynSeq_t *seq) { return seq->nElems; } STATIC_INLINE Diderot_DynSeq_t *Diderot_DynSeqAlloc (size_t elemSz, int initialSz) { Diderot_DynSeq_t *seq = NEW(Diderot_DynSeq_t); seq->base = 0; seq->nElems = initialSz; seq->size = initialSz + 8; // FIXME: be smarter about padding seq->data = CheckedAlloc (elemSz * seq->size); return seq; } STATIC_INLINE Diderot_DynSeq_t *Diderot_DynSeqMk (size_t elemSz, int nElems, void *elems) { Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); unsigned char *p = (unsigned char *)seq->data; unsigned char *q = (unsigned char *)elems; for (int i = 0; i < nElems; i++) { memcpy(p, q, elemSz); p += elemSz; q += elemSz; } return seq; } STATIC_INLINE void *Diderot_DynSeqAddr (size_t elemSz, Diderot_DynSeq_t *seq, int i) { i = (seq->base + i) % seq->size; return ((char *)(seq->data) + elemSz * i); } //! append an element to a sequence Diderot_DynSeq_t *Diderot_DynSeqAppend (size_t elemSz, Diderot_DynSeq_t *, void *); //! prepend an element to a sequence Diderot_DynSeq_t *Diderot_DynSeqPrepend (size_t elemSz, void *, Diderot_DynSeq_t *); //! concatenate two sequences Diderot_DynSeq_t *Diderot_DynSeqConcat (size_t elemSz, Diderot_DynSeq_t *, Diderot_DynSeq_t *); //! \brief copy the elements of a sequence to an array //! \param elemSz the size of the sequence elements in bytes //! \param dst the destination array //! \param seq the source sequence //! \return the address of the element that follows the array void *Diderot_DynSeqCopy (size_t elemSz, void *dst, Diderot_DynSeq_t *seq); #endif /* !_DIDEROT_DYN_SEQ_H_ */
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |