|
| 1 | +/* |
| 2 | + * set.lmn - Set module |
| 3 | + * |
| 4 | + * Copyright (c) 2017, Ueda Laboratory LMNtal Group <lmntal@ueda.info.waseda.ac.jp> |
| 5 | + * All rights reserved. |
| 6 | + * |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are |
| 9 | + * met: |
| 10 | + * |
| 11 | + * 1. Redistributions of source code must retain the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer. |
| 13 | + * |
| 14 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | + * notice, this list of conditions and the following disclaimer in |
| 16 | + * the documentation and/or other materials provided with the |
| 17 | + * distribution. |
| 18 | + * |
| 19 | + * 3. Neither the name of the Ueda Laboratory LMNtal Group nor the |
| 20 | + * names of its contributors may be used to endorse or promote |
| 21 | + * products derived from this software without specific prior |
| 22 | + * written permission. |
| 23 | + * |
| 24 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 27 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 28 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 29 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 30 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 34 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | + * |
| 36 | + */ |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +/* |
| 41 | +NAME |
| 42 | + Set module |
| 43 | + |
| 44 | +SYNOPSIS |
| 45 | + |
| 46 | +AUTHOR |
| 47 | + Yutaro Tsunekawa |
| 48 | + |
| 49 | +HISTORY |
| 50 | + 2017/05/03(Wed) |
| 51 | +*/ |
| 52 | + |
| 53 | +{ |
| 54 | + module(set). |
| 55 | + |
| 56 | + Ret = set.init :- Ret = set_empty. |
| 57 | + |
| 58 | + set.free(Set) :- class(Set, "set") | |
| 59 | + '$callback'('cb_set_free', Set). |
| 60 | + |
| 61 | + Ret = set.insert(Set, Val) :- |
| 62 | + '$callback'('cb_set_insert', Set, Val, Ret). |
| 63 | + |
| 64 | + Ret = set.find(set_empty, Val, Res) :- ground(Val) | Ret = set_empty, Res = none. |
| 65 | + |
| 66 | + Ret = set.find(set_empty, {$v[]}, Res) :- | Ret = set_empty, Res = none. |
| 67 | + |
| 68 | + Ret = set.find(Set, Val, Res) :- class(Set, "set") | |
| 69 | + '$callback'('cb_set_find', Set, Val, Res, Ret). |
| 70 | + |
| 71 | + Ret = set.to_list(set_empty) :- Ret = []. |
| 72 | + |
| 73 | + Ret = set.to_list(Set) :- class(Set, "set") | |
| 74 | + '$callback'('cb_set_to_list', Set, Ret). |
| 75 | + |
| 76 | + Ret = set.copy(set_empty, S) :- Ret = set_empty, S = set_empty. |
| 77 | + |
| 78 | + Ret = set.copy(S0, S1) :- class(S0, "set") | |
| 79 | + '$callback'('cb_set_copy', S0, S1, Ret). |
| 80 | + |
| 81 | + Ret = set.erase(Set, Val) :- class(Set, "set") | |
| 82 | + '$callback'('cb_set_erase', Set, Val, Ret). |
| 83 | + |
| 84 | + Ret = set.erase(set_empty, $v) :- unary($v) | |
| 85 | + Ret = set_empty. |
| 86 | + |
| 87 | + Ret = set.union(Set0, Set1) :- class(Set0, "set"), class(Set1, "set") | |
| 88 | + '$callback'('cb_set_union', Set0, Set1, Ret). |
| 89 | + |
| 90 | + Ret = set.union(Set, set_empty) :- Ret = Set. |
| 91 | + |
| 92 | + Ret = set.union(set_empty, Set) :- Ret = Set. |
| 93 | + |
| 94 | + Ret = set.intersect(Set0, Set1) :- class(Set0, "set"), class(Set1, "set") | |
| 95 | + '$callback'('cb_set_intersect', Set0, Set1, Ret). |
| 96 | + |
| 97 | + Ret = set.intersect(Set, set_empty) :- Ret = set_empty, free(Set). |
| 98 | + |
| 99 | + Ret = set.intersect(set_empty, Set) :- Ret = set_empty, free(Set). |
| 100 | + |
| 101 | + Ret = set.diff(set_empty, set_empty) :- |
| 102 | + Ret = set_empty. |
| 103 | + |
| 104 | + Ret = set.diff(set_empty, S1) :- class(S1, "set") | |
| 105 | + Ret = set_empty. |
| 106 | + |
| 107 | + Ret = set.diff(S0, set_empty) :- class(S0, "set") | |
| 108 | + Ret = S0. |
| 109 | + |
| 110 | + Ret = set.diff(S0, S1) :- class(S0, "set"), class(S1, "set") | |
| 111 | + '$callback'('cb_set_diff', S0, S1, Ret). |
| 112 | +} |
0 commit comments