项目作者: CodiePP

项目描述 :
Indexed predicates in Prolog
高级语言: C
项目地址: git://github.com/CodiePP/predidx.git
创建时间: 2021-03-22T10:25:21Z
项目社区:https://github.com/CodiePP/predidx

开源协议:GNU General Public License v3.0

下载


building the module for SWI Prolog

Indexed Predicates

Installation

  1. aclocal --force && autoheader --force && autoconf --force
  2. ./configure
  3. make swi

then, I copy the results to a module directory that SWI Prolog finds:

  1. mkdir -v -p ~/lib/sbcl
  2. cp -v predidx-* ~/lib/sbcl/predidx
  3. cp -v src/predidx.qlf ~/lib/sbcl/

Update the swipl config file:

  • SWI-Prolog version < 8.1.15

    (add the following to ~/.swiplrc)
    1. echo ":- assertz(file_search_path(sbcl,'${HOME}/lib/sbcl'))." >> ${HOME}/.swiplrc
  • SWI-Prolog version >= 8.1.15

    run the following from the terminal
    1. echo ":- assertz(file_search_path(sbcl,'${HOME}/lib/sbcl'))." >> ${HOME}/.config/swi-prolog/init.pl

Description

Prolog predicates in tables indexed by their row number. Behind the scenes
this is the same as an array of a structure type in C.

  1. tbl_create('table_name', [max_rows(1_000_000), realloc_rows(10_000)], Tid).

so, indexing from 0 to 999_999 is OK

  1. tbl_has(Tid, 42).
  2. tbl_has(Tid, X). % enumerate
  1. tbl_get(Tid, 42, X).
  1. tbl_set(Tid, 42, 'something').
  1. tbl_unset(Tid, 42).
  2. tbl_has(Tid, 42). % => false

example usage

  1. :- use_module(sbcl(predidx)).
  2. t1 :-
  3. Tname = 'likes',
  4. tbl_create(Tname, [max_rows(10000),realloc_rows(100),structure(['int32'])], Tid),
  5. format("created table '~a' with id = ~p~n", [Tname, Tid]).