| 1 | // -*- mode: csharp; encoding: utf-8; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
|---|
| 2 | // vim:set ft=cs fenc=utf-8 ts=4 sw=4 sts=4 et: |
|---|
| 3 | // $Id$ |
|---|
| 4 | /* Linx |
|---|
| 5 | * Library that Integrates .NET with eXtremes |
|---|
| 6 | * Copyright © 2008-2009 Takeshi KIRIYA, XSpect Project <takeshik@users.sf.net> |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
|---|
| 10 | * copy of this software and associated documentation files (the "Software"), |
|---|
| 11 | * to deal in the Software without restriction, including without limitation |
|---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
|---|
| 14 | * Software is furnished to do so, subject to the following conditions: |
|---|
| 15 | * |
|---|
| 16 | * The above copyright notice and this permission notice shall be included in |
|---|
| 17 | * all copies or substantial portions of the Software. |
|---|
| 18 | * |
|---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|---|
| 25 | * IN THE SOFTWARE. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | using System; |
|---|
| 29 | using System.Collections.Generic; |
|---|
| 30 | using System.Linq; |
|---|
| 31 | using System.IO; |
|---|
| 32 | using Achiral.Extension; |
|---|
| 33 | |
|---|
| 34 | namespace XSpect.Extension |
|---|
| 35 | { |
|---|
| 36 | public static class NumericUtil |
|---|
| 37 | { |
|---|
| 38 | public static void Times(this Int32 self, Action action) |
|---|
| 39 | { |
|---|
| 40 | if (self < 0) |
|---|
| 41 | { |
|---|
| 42 | return; |
|---|
| 43 | } |
|---|
| 44 | for (Int32 i = 0; i < self; ++i) |
|---|
| 45 | { |
|---|
| 46 | action(); |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public static void Times(this Int32 self, Action<Int32> action) |
|---|
| 51 | { |
|---|
| 52 | if (self < 0) |
|---|
| 53 | { |
|---|
| 54 | return; |
|---|
| 55 | } |
|---|
| 56 | for (Int32 i = 0; i < self; ++i) |
|---|
| 57 | { |
|---|
| 58 | action(i); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public static IEnumerable<Int32> Step(this Int32 self, Int32 limit) |
|---|
| 63 | { |
|---|
| 64 | return Step(self, limit, 1); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | public static IEnumerable<Int32> Step(this Int32 self, Int32 limit, Int32 step) |
|---|
| 68 | { |
|---|
| 69 | for (Int32 i = self; i <= limit; i += step) |
|---|
| 70 | { |
|---|
| 71 | yield return i; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | public static void Times(this Int64 self, Action action) |
|---|
| 76 | { |
|---|
| 77 | if (self < 0) |
|---|
| 78 | { |
|---|
| 79 | return; |
|---|
| 80 | } |
|---|
| 81 | for (Int64 i = 0; i < self; ++i) |
|---|
| 82 | { |
|---|
| 83 | action(); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public static void Times(this Int64 self, Action<Int64> action) |
|---|
| 88 | { |
|---|
| 89 | if (self < 0) |
|---|
| 90 | { |
|---|
| 91 | return; |
|---|
| 92 | } |
|---|
| 93 | for (Int64 i = 0; i < self; ++i) |
|---|
| 94 | { |
|---|
| 95 | action(i); |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | public static IEnumerable<Int64> Step(this Int64 self, Int64 limit) |
|---|
| 100 | { |
|---|
| 101 | return Step(self, limit, 1); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public static IEnumerable<Int64> Step(this Int64 self, Int64 limit, Int64 step) |
|---|
| 105 | { |
|---|
| 106 | for (Int64 i = self; i <= limit; i += step) |
|---|
| 107 | { |
|---|
| 108 | yield return i; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | } |
|---|