54 lines
1.0 KiB
C#
54 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ServerCore;
|
|
|
|
public class InstantIdGeneratorWith32Bit
|
|
{
|
|
private UInt32 m_index = 0;
|
|
public InstantIdGeneratorWith32Bit()
|
|
{
|
|
}
|
|
|
|
public UInt32 nextId()
|
|
{
|
|
Interlocked.Increment(ref m_index);
|
|
|
|
if(m_index == UInt32.MaxValue)
|
|
{
|
|
throw new OverflowException("UInt32.MaxValue has been reached, at InstantIdGeneratorWith32Bit.nextId() !!!");
|
|
}
|
|
|
|
return m_index;
|
|
}
|
|
|
|
}//InstantIdGeneratorWith32Bit
|
|
|
|
public class InstantIdGeneratorWith64Bit
|
|
{
|
|
private UInt64 m_index = 0;
|
|
public InstantIdGeneratorWith64Bit()
|
|
{
|
|
}
|
|
|
|
public UInt64 nextId()
|
|
{
|
|
Interlocked.Increment(ref m_index);
|
|
|
|
if (m_index >= UInt64.MaxValue)
|
|
{
|
|
throw new OverflowException("UInt64.MaxValue has been reached, at InstantIdGeneratorWith64Bit.nextId() !!!");
|
|
}
|
|
|
|
return m_index;
|
|
}
|
|
|
|
}//InstantIdGeneratorWith64Bit
|