view run/a/associative_array_19_C.d @ 1090:f4e98d870b57

pre DMD-0.163 review
author thomask
date Thu, 20 Jul 2006 14:47:29 +0000
parents 03b5056496f1
children b8c0195059d9
line wrap: on
line source

// $HeadURL$
// $Date$
// $Author$

// @author@	Sebastian Beschke <s.beschke@gmx.de>
// @date@	2005-03-25
// @uri@	news:e03hkt$2lvf$1@digitaldaemon.com

// @WARNING@ direct access to Phobos' GC

module dstress.run.a.associative_array_19_C;

import std.gc;

union Key{
	char x;
	ubyte[3] y;
}

class Payload {
	this(Key value) {
		value.x += 1;
		_value = value;
	}

	Key value() {
		return _value;
	}

	Key _value;
}

int main(){
	Payload[Key] aa;

	Key[] allKeys;
	static Key a = { 'a' };
	static Key b = { 'b' };
	static Key c = { 'c' };
	allKeys ~= a;
	allKeys ~= b;
	allKeys ~= c;

	foreach(Key key; allKeys) {
		aa[key] = new Payload(key);
	}

	for(size_t step = 0; step < 10000; step++){
		foreach(Key key; allKeys) {
			if(!(key in aa)){
				assert(0);
			}
			Payload p = aa[key];
			if(p.value.x != key.x + 1){
				assert(0);
			}
		}
		std.gc.fullCollect();
	}

	return 0;
}