using
System;
using
System.Collections.Generic;
public
class
Van_Emde_Boas {
public
int
universe_size;
public
int
minimum;
public
int
maximum;
public
Van_Emde_Boas summary;
public
List<Van_Emde_Boas> clusters;
public
Van_Emde_Boas(
int
size)
{
universe_size = size;
minimum = -1;
maximum = -1;
if
(size <= 2) {
summary =
null
;
clusters =
new
List<Van_Emde_Boas>(0);
}
else
{
int
no_clusters
= (
int
)Math.Ceiling(Math.Sqrt(size));
summary =
new
Van_Emde_Boas(no_clusters);
clusters
=
new
List<Van_Emde_Boas>(no_clusters);
for
(
int
i = 0; i < no_clusters; i++) {
clusters.Add(
new
Van_Emde_Boas(
(
int
)Math.Ceiling(Math.Sqrt(size))));
}
}
}
public
int
high(
int
x)
{
int
div = (
int
)Math.Ceiling(Math.Sqrt(universe_size));
return
x / div;
}
public
int
low(
int
x)
{
int
mod = (
int
)Math.Ceiling(Math.Sqrt(universe_size));
return
x % mod;
}
public
int
generate_index(
int
x,
int
y)
{
int
ru = (
int
)Math.Ceiling(Math.Sqrt(universe_size));
return
x * ru + y;
}
}
public
class
Main_Program {
public
static
int
VEB_minimum(Van_Emde_Boas helper)
{
return
(helper.minimum == -1 ? -1 : helper.minimum);
}
public
static
int
VEB_maximum(Van_Emde_Boas helper)
{
return
(helper.maximum == -1 ? -1 : helper.maximum);
}
static
void
insert(Van_Emde_Boas helper,
int
key)
{
if
(helper.minimum == -1) {
helper.minimum = key;
helper.maximum = key;
}
else
{
if
(key < helper.minimum) {
int
temp = helper.minimum;
helper.minimum = key;
key = temp;
}
if
(helper.universe_size > 2) {
if
(VEB_minimum(helper.clusters[helper.high(key)])
== -1) {
insert(helper.summary,
helper.high(key));
helper.clusters[helper.high(key)]
.minimum
= helper.low(key);
helper.clusters[helper.high(key)]
.maximum
= helper.low(key);
}
else
{
insert(helper.clusters[
helper.high(key)],
helper.low(key));
}
}
if
(key > helper.maximum) {
helper.maximum = key;
}
}
}
public
static
bool
isMember(Van_Emde_Boas helper,
int
key)
{
if
(helper.universe_size < key)
{
return
false
;
}
if
(helper.minimum == key || helper.maximum == key)
{
return
true
;
}
else
{
if
(helper.universe_size == 2)
{
return
false
;
}
else
{
return
isMember(helper.clusters[helper.high(key)], helper.low(key));
}
}
}
public
static
void
Main() {
Van_Emde_Boas veb =
new
Van_Emde_Boas(8);
insert(veb, 2);
insert(veb, 3);
insert(veb, 6);
Console.WriteLine(isMember(veb,3));
Console.WriteLine(isMember(veb,4));
Console.WriteLine(VEB_maximum(veb));
Console.WriteLine(VEB_minimum(veb));
}
}