//----------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All Rights Reserved. // //----------------------------------------------------------------------------- using System.Collections.Generic; using System.Linq; using System.Threading; namespace Chalice { public class ImmutableList { private List list; public ImmutableList() { list = new List(); } public ImmutableList(IEnumerable elems) { list = new List(elems); } public ImmutableList Append(ImmutableList other) { var res = new ImmutableList(); res.list.AddRange(list); res.list.AddRange(other.list); return res; } public E At(int index) { return list[index]; } public ImmutableList Take(int howMany) { var res = new ImmutableList(this.list.Take(howMany)); return res; } public ImmutableList Drop(int howMany) { var res = new ImmutableList(this.list.Skip(howMany)); return res; } public int Length { get { return list.Count; } } public static ImmutableList Range(int min, int max) { ImmutableList l = new ImmutableList(); for (int i = min; i < max; i++) { l.list.Add(i); } return l; } } public class ChannelBuffer { private Queue contents = new Queue(); public void Add(E e) { lock (this) { contents.Enqueue(e); Monitor.Pulse(this); } } public E Remove() { lock (this) { while (contents.Count == 0) { Monitor.Wait(this); } E e = contents.Dequeue(); return e; } } } public class ChalicePrint { public void Int(int x) { System.Console.WriteLine(x); } public void Bool(bool x) { System.Console.WriteLine(x); } } }