summaryrefslogtreecommitdiff
path: root/anthy/record.h
blob: df76feaa9dfb1ac015f5dddc812a193a5de127fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* 学習の履歴などを保存するデータベース */
#ifndef _record_h_included_
#define _record_h_included_
/*
 * データベースは名前をもつ複数のsectionから構成され各セクションは
 * 文字列をキーとして高速に取り出すことができるrowからなる。
 *
 * データベースはカレントsectionやカレントrowなどの状態を持ち
 * 操作はそれに対して行われる。
 * section中のrowは順序関係をもっている
 * その順序関係とは別にLRUの順序をもっている
 */

#include "xstr.h"

/*
 * カレントsectionを設定する
 * name: sectionの名前
 * create_if_not_exist: そのsectionがなければ作るかどうかのフラグ
 * 返り値: 成功 0 、失敗 -1
 * 失敗の時にはカレントsectionは無効になる
 * 常にカレントrowは無効になる
 */
int anthy_select_section(const char *name, int create_if_not_exist);

/*
 * カレントsection中からnameのrowをカレントrowにする
 * name: rowの名前
 * create_if_not_exist: そのrowがなければ作るかどうかのフラグ
 * 返り値: 成功 0 、失敗 -1
 * 失敗の時にはカレントrowは無効になる
 */
int anthy_select_row(xstr *name, int create_if_not_exist);

/*
 * カレントsection中からnameに最も長い文字数でマッチする
 * 名前のrowをカレントrowにする
 * name: rowの名前
 * 返り値: 成功 0 、失敗 -1
 * 失敗の時にはにカレントrowは無効になる
 */
int anthy_select_longest_row(xstr *name);

/*
 * カレントsection中の最初のrowをカレントrowにする
 * 返り値: 成功 0 、失敗 -1
 * 失敗の時にはカレントrowは無効になる
 */
int anthy_select_first_row(void);

/*
 * カレントrowの次のrowをカレントrowにする
 * 返り値: 成功 0 、失敗 -1
 * カレントrowに対する変更があっても、ファイルには保存されない
 * 失敗の時にはカレントrowは無効になる
 */
int anthy_select_next_row(void);

/*
 * カレントsectionを解放する
 * 常にカレントsection,rowは無効になる
 */
void anthy_release_section(void);

/*
 * カレントsectionのLRUリストの先頭からcount個以降を解放する
 * 常にカレントrowは無効になる
 */
void anthy_truncate_section(int count);


/* 現在のrowに対する操作 */
xstr *anthy_get_index_xstr(void);
int anthy_get_nr_values(void);
int anthy_get_nth_value(int );
xstr *anthy_get_nth_xstr(int );/* internされているxstrが返される */

void anthy_set_nth_value(int nth, int val);
void anthy_set_nth_xstr(int nth, xstr *xs);/* 内部でコピーされる */

void anthy_truncate_row(int nth);/* To Be Implemented */

/*
 * カレントrowを解放する。終了後のカレントrowは不定
 * 常にカレントrowは無効になる
 */
void anthy_release_row(void);

/*
 * カレントrowをLRUの先頭の方へもってくる
 * 常にカレントrowは無効になる
 */
int anthy_mark_row_used(void);


void anthy_reload_record(void);

#endif