Advertisement
Guest User

Untitled

a guest
Feb 17th, 2012
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.65 KB | None | 0 0
  1. module main;
  2.  
  3. import std.algorithm;
  4. import std.stdio;
  5. import std.range;
  6.  
  7. Foo[uint] foo;
  8.  
  9. auto sorted(T)(T t)
  10. {
  11.     sort(t);
  12.     return t;
  13. }
  14.  
  15. void main()
  16. {
  17.     add( new Foo(1) );
  18.     add( new Foo(2) );
  19.     add( new Foo(3) );
  20.     add( new Foo(4) );
  21.    
  22.     writeln("length: ", foo.length);
  23.    
  24.     foreach (key; retro(sorted(foo.keys)))
  25.     {
  26.         if(key >= 2 && key <= 3)
  27.         {
  28.             remove(foo[key]);
  29.             continue;
  30.         }
  31.         writeln("k: ", key);        
  32.     }
  33.    
  34.     writeln("length: ", foo.length);
  35. }
  36.  
  37. void add(Foo f)
  38. {
  39.     foo[f.id] = f;
  40. }
  41.  
  42. void remove(Foo f)
  43. {
  44.     foo.remove(f.id);
  45. }
  46.  
  47. class Foo
  48. {
  49.     uint id;
  50.    
  51.     this(uint id)
  52.     {
  53.         this.id = id;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement