1 文本格式
using System;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Hash<K, V> : Hashtable<K>
{
private List<V> els { get; set; } = new List<V>();
public Hash(int nh, int nm) : base(nh, nm)
{
this.els = new List<V>(nm);
}
public void set(K key, V el)
{
els[iset(key)] = el;
}
public int get(K key, ref V el)
{
int ll = iget(key);
if (ll < 0)
{
return 0;
}
el = els[ll];
return 1;
}
public int get(K key, V[] el, int on)
{
int ll = iget(key);
if (ll < 0) return 0;
el[on] = els[ll];
return 1;
}
public V get(K key)
{
int ll = iget(key);
if (ll < 0) return default(V);
return els[ll];
}
public V this[in K key]
{
get
{
int ll = iget(key);
if (ll < 0)
{
ll = iset(key);
els[ll] = default(V);
}
return els[ll];
}
set
{
int ll = iget(key);
els[ll] = value;
}
}
public int count(K key)
{
int ll = iget(key);
return (ll < 0 ? 0 : 1);
}
public int erase(K key)
{
return (ierase(key) < 0 ? 0 : 1);
}
}
}
2 代码格式
using System;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Hash<K, V> : Hashtable<K>
{
private List<V> els { get; set; } = new List<V>();
public Hash(int nh, int nm) : base(nh, nm)
{
this.els = new List<V>(nm);
}
public void set(K key, V el)
{
els[iset(key)] = el;
}
public int get(K key, ref V el)
{
int ll = iget(key);
if (ll < 0)
{
return 0;
}
el = els[ll];
return 1;
}
public int get(K key, V[] el, int on)
{
int ll = iget(key);
if (ll < 0) return 0;
el[on] = els[ll];
return 1;
}
public V get(K key)
{
int ll = iget(key);
if (ll < 0) return default(V);
return els[ll];
}
public V this[in K key]
{
get
{
int ll = iget(key);
if (ll < 0)
{
ll = iset(key);
els[ll] = default(V);
}
return els[ll];
}
set
{
int ll = iget(key);
els[ll] = value;
}
}
public int count(K key)
{
int ll = iget(key);
return (ll < 0 ? 0 : 1);
}
public int erase(K key)
{
return (ierase(key) < 0 ? 0 : 1);
}
}
}