Click here to Skip to main content

Comments by Leslie Zhai (Top 2 by date)

Xiang Zhai at 2-Aug-12 21:28pm View
   
Thank CPanllini, it might be MYSQL mysql static struct object, then mysql_init(&mysql), it is bad 'an earlier' link to static mysql struct object;
 
But in my situation, MYSQL* mysql = mysql_init(NULL); it my_malloc mysql pointer object, it is suitable to set the funtion pointer address.
xiangzhai at 7-Apr-11 4:25am View
   
Deleted
DeTrend.cs library in C#

<pre lang="cs">
// TODO: DeTrend class acts like mathwords detrend(...)
public class DeTrend
{
public DeTrend(int nWindowSize)
{
m_nWindowSize = nWindowSize;
m_TrendList = new LinkedList<float>();
}
 
public void Dispose()
{
if (null != m_TrendList) m_TrendList.Clear(); m_TrendList = null;
}
 
public void Update(float[] inY, float[] outY, int nPointSize)
{
int i;
m_nPointSize = nPointSize;
if (m_nPointSize < m_nWindowSize)
{
throw new Exception("nPointSize < nWindowSize");
}
for (i = 0; i < m_nPointSize; i++)
{
m_TrendList.AddLast(inY[i]);
}
if (m_bFirstCall)
{
m_CurIter = m_TrendList.First;
}
for (i = 0; i < m_nPointSize; i++)
{
// FIXME: m_CurIter became to null after the first call
outY[i] = m_CurIter.Value - m_PreNMeanVal();
m_CurIter = m_CurIter.Next;
}
i = m_nPointSize - m_nWindowSize;
while (0 != i)
{
m_TrendList.RemoveFirst();
i--;
}
m_bFirstCall = false;
}
 
#region Private Variable
private bool m_bFirstCall = true;
private int m_nWindowSize = 101;
private int m_nPointSize = 200;
private LinkedList<float> m_TrendList = null;
private LinkedListNode<float> m_CurIter = null;
#endregion
 
// XXX: What is the Preview N Mean Value?
private float m_PreNMeanVal()
{
float nRet = 0.0f;
float nTotal = 0.0f;
int i, nCount = 0;
LinkedListNode<float> iter;
for (iter = m_TrendList.First; m_CurIter != iter; ) iter = iter.Next;
for (i = 0; i < m_nWindowSize && iter != m_TrendList.First; i++)
{
nTotal += iter.Value;
nCount++;
iter = iter.Previous;
}
if (0 == nCount) return nRet;
nRet = nTotal / nCount;
return nRet;
}
}
</pre>

 
LibDeTrend.cpp can be DllImport by C#

<pre lang="cpp">
...
#include <list>
 
///////////////////////////////////////////////////////////////////////////////
// DeTrend Class
namespace CCTEC
{
class DeTrend
{
// Construct / Destruct
public:
DeTrend(int nWindowSize)
{
m_nWindowSize = nWindowSize;
m_bFirstCall = true;
}
~DeTrend() { m_TrendList.clear(); }
 
// Operation
public:
void Update(float *inY, float *outY, int nPointSize)
{
int i;
m_nPointSize = nPointSize;
if (m_nPointSize < m_nWindowSize) throw "WindowSize > PointSize";
for (i = 0; i < m_nPointSize; i++)
{
m_TrendList.push_back(inY[i]);
}
if (m_bFirstCall)
{
m_CurIter = m_TrendList.begin();
}
for (i = 0; i < m_nPointSize; i++, m_CurIter++)
{
outY[i] = *m_CurIter - m_PreNMeanVal();
}
i = m_nPointSize - m_nWindowSize;
while (i)
{
m_TrendList.pop_front();
i--;
}
m_bFirstCall = false;
}
 
// Attribute
private:
int m_nWindowSize;
int m_nPointSize;
bool m_bFirstCall;
std::list<float> m_TrendList;
std::list<float>::iterator m_CurIter;
 
// Operation
private:
float m_PreNMeanVal()
{
float nRet = 0.0f;
float nTotal = 0.0f;
int i, nCount = 0;
std::list<float>::iterator iter;
for (iter = m_TrendList.begin(); m_CurIter != iter;) iter++;
for (i = 0; i < m_nWindowSize && iter != m_TrendList.begin(); i++, iter--)

Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 1 Jan 1900
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid