1/* BEGIN LICENSE BLOCK 2 * Version: CMPL 1.1 3 * 4 * The contents of this file are subject to the Cisco-style Mozilla Public 5 * License Version 1.1 (the "License"); you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License 7 * at www.eclipse-clp.org/license. 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and limitations 12 * under the License. 13 * 14 * The Original Code is The ECLiPSe Constraint Logic Programming System. 15 * The Initial Developer of the Original Code is Cisco Systems, Inc. 16 * Portions created by the Initial Developer are 17 * Copyright (C) 2001-2006 Cisco Systems, Inc. All Rights Reserved. 18 * 19 * Contributor(s): Warwick Harvey, IC-Parc 20 * 21 * END LICENSE BLOCK */ 22/*-------------------------------------------------------------------- 23** 24** Header file for low-level C functions implementing bitmaps. 25** 26** System: ECLiPSe Constraint Logic Programming System 27** Author/s: Warwick Harvey, IC-Parc 28** 29** This file provides some definitions useful for C modules wishing to 30** utilise the functions provided by the bitmap C module. 31** 32**-------------------------------------------------------------------*/ 33 34 35/* 36** Result codes. 37*/ 38 39#define RES_CHANGED 0x1 /* Domain was updated */ 40#define RES_SLACK 0x2 /* Bound given is not tight */ 41#define RES_EMPTY 0x4 /* Domain is empty */ 42 43 44/* 45** Macros for testing result codes. 46*/ 47 48#define Result_Is_Empty(result) (((result) & RES_EMPTY) == RES_EMPTY) 49#define Result_Is_Non_Empty(result) (((result) & RES_EMPTY) == 0) 50#define Result_Is_Change(result) (((result) & RES_CHANGED) == RES_CHANGED) 51#define Result_Is_Slack(result) (((result) & RES_SLACK) == RES_SLACK) 52 53 54/* 55** Some fake macros to make bitmaps look a bit like their own types - 56** cf. sepia.h 57*/ 58 59 /* Use the string tag. */ 60#define TBITMAP TSTRG 61 62 /* Type check. */ 63#define Check_Bitmap(item) Check_String(item) 64 65 /* Bitmap unifications. */ 66#define Request_Unify_Bitmap(vx,tx,vy) Request_Unify_Type(vx,tx,wptr,vy,TBITMAP) 67#define Return_Unify_Bitmap(vx,tx,vy) Return_Unify_Type(vx,tx,wptr,vy,TBITMAP) 68 69 /* Return a bitmap or an integer. */ 70 /* NOTE: these clobber return variable --- use only with fresh variables. */ 71#define Return_Bitmap(v, t, b) \ 72 { \ 73 value bval; \ 74 type btype ; \ 75 bval.wptr = b ; \ 76 btype.kernel = TBITMAP; \ 77 Unify_Pw(v, t, bval, btype); \ 78 } 79#define Return_Integer(v, t, i) \ 80 { \ 81 v.ptr->val.nint = i; \ 82 v.ptr->tag.kernel = TINT; \ 83 } 84 85 86/* 87** Function prototypes. 88*/ 89 90extern int p_create_bitmap(value vmin, type tmin, value vmax, type tmax, value vbm, type tbm); 91extern word create_bitmap(word min, word max, uword **bm_ptr); 92extern int p_set_bitmap_lwb(value vbm, type tbm, value vmin, type tmin, value vresult, type tresult, value vnew_bm, type tnew_bm); 93extern word set_bitmap_lwb(uword *bitmap, word min, uword **new_bm_ptr); 94extern int p_set_bitmap_upb(value vbm, type tbm, value vmax, type tmax, value vresult, type tresult, value vnew_bm, type tnew_bm); 95extern word set_bitmap_upb(uword *bitmap, word max, uword **new_bm_ptr); 96extern int p_remove_bitmap_element(value vbm, type tbm, value vel, type tel, value vresult, type tresult, value vnew_bm, type tnew_bm); 97extern word remove_bitmap_element(uword *bitmap, word el, uword **new_bm_ptr); 98extern int p_remove_bitmap_range(value vbm, type tbm, value vlo, type tlo, value vhi, type thi, value vresult, type tresult, value vnew_bm, type tnew_bm); 99extern word remove_bitmap_range(uword *bitmap, word lo0, word hi0, uword **new_bm_ptr); 100extern int p_bitmap_intersect_into(value vbm, type tbm, value vbm2, type tbm2, value vresult, type tresult, value vnew_bm, type tnew_bm); 101extern word bitmap_intersect_into(uword *bitmap, uword *bitmap2, word offset_adj, uword **new_bm_ptr); 102extern int p_bitmap_shifted_intersect_into(value vbm, type tbm, value vbm2, type tbm2, value vshift, type tshift, value vresult, type tresult, value vnew_bm, type tnew_bm); 103extern word bitmap_shifted_intersect_into(uword *bitmap, uword *bitmap2, word shift, uword **new_bm_ptr); 104extern int p_bitmaps_have_non_empty_intersection(value vbm, type tbm, value vbm2, type tbm2); 105extern int bitmaps_have_non_empty_intersection(uword *bitmap, uword *bitmap2); 106extern int p_bitmap_union(value vbm, type tbm, value vbm2, type tbm2, value vnew_bm, type tnew_bm); 107extern word bitmap_union(uword *bitmap, uword *bitmap2, uword **new_bm_ptr); 108extern int p_copy_bitmap(value vbm, type tbm, value vnew_bm, type tnew_bm); 109extern void copy_bitmap(uword *bitmap, uword **new_bm_ptr); 110extern int p_copy_bitmap_shifted(value vbm, type tbm, value vshift, type tshift, value vnew_bm, type tnew_bm); 111extern void copy_bitmap_shifted(uword *bitmap, word shift, uword **new_bm_ptr); 112extern int p_bitmap_range(value vbm, type tbm, value vmin, type tmin, value vmax, type tmax); 113extern word bitmap_range(uword *bitmap, word *min_ptr, word *max_ptr); 114extern int p_get_bitmap_lwb(value vbm, type tbm, value vmin, type tmin); 115extern word get_bitmap_lwb(uword *bitmap, word *min_ptr); 116extern int p_get_bitmap_upb(value vbm, type tbm, value vmax, type tmax); 117extern word get_bitmap_upb(uword *bitmap, word *max_ptr); 118extern int p_next_greater_member(value vbm, type tbm, value vcurr, type tcurr, value vnext, type tnext); 119extern word next_greater_member(uword *bitmap, word curr, word *next_ptr); 120extern int p_next_smaller_member(value vbm, type tbm, value vcurr, type tcurr, value vnext, type tnext); 121extern word next_smaller_member(uword *bitmap, word curr, word *next_ptr); 122extern int p_next_greater_non_member(value vbm, type tbm, value vcurr, type tcurr, value vnext, type tnext); 123extern word next_greater_non_member(uword *bitmap, word curr, word *next_ptr); 124extern int p_next_smaller_non_member(value vbm, type tbm, value vcurr, type tcurr, value vnext, type tnext); 125extern word next_smaller_non_member(uword *bitmap, word curr, word *next_ptr); 126extern int p_bitmap_size(value vbm, type tbm, value vsize, type tsize); 127extern word bitmap_size(uword *bitmap); 128extern int p_bitmap_contains(value vbm, type tbm, value vel, type tel); 129extern word bitmap_contains(uword *bitmap, word el); 130extern int p_bitmap_contains_range(value vbm, type tbm, value vmin, type tmin, value vmax, type tmax); 131extern word bitmap_contains_range(uword *bitmap, word min, word max); 132extern int p_compare_bitmaps(value vres, type tres, value vbm, type tbm, value vbm2, type tbm2); 133extern word compare_bitmaps(uword *bitmap, uword *bitmap2, int *res_ptr); 134 135