-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
IndexProgressor.java
153 lines (140 loc) · 5.74 KB
/
IndexProgressor.java
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.storageengine.api.schema;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.LabelSet;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.values.storable.Value;
/**
* The index progressor is a cursor like class, which allows controlled progression through the entries of an index.
* In contrast to a cursor, the progressor does not hold value state, but rather attempts to write the next entry to a
* Client. The client can them accept the entry, in which case next() returns, or reject it, in which case the
* progression continues until an acceptable entry is found or the progression is done.
*
* A Progressor is expected to feed a single client, which is setup for example in the constructor. The typical
* interaction goes something like
*
* -- query(client) -> INDEX
* progressor = new Progressor( client )
* client.initialize( progressor, ... )
*
* -- next() --> client
* client ---- next() --> progressor
* <-- accept() --
* :false
* <-- accept() --
* :false
* <-- accept() --
* :true
* client <--------------
* <-----------
*/
public interface IndexProgressor extends AutoCloseable
{
/**
* Progress through the index until the next accepted entry. Entries are feed to a Client, which
* is setup in an implementation specific way.
*
* @return true if an accepted entry was found, false otherwise
*/
boolean next();
/**
* Close the progressor and all attached resources. Idempotent.
*/
@Override
void close();
/**
* Client which accepts nodes and some of their property values.
*/
interface NodeValueClient
{
/**
* Setup the client for progressing using the supplied progressor. The values feed in accept map to the
* propertyIds provided here. Called by index implementation.
* @param descriptor The descriptor
* @param progressor The progressor
* @param query The query of this progression
*/
void initialize( IndexDescriptor descriptor, IndexProgressor progressor,
IndexQuery[] query );
/**
* Accept the node id and values of a candidate index entry. Return true if the entry is
* accepted, false otherwise.
* @param reference the node id of the candidate index entry
* @param values the values of the candidate index entry
* @return true if the entry is accepted, false otherwise
*/
boolean acceptNode( long reference, Value... values );
}
/**
* Client which accepts nodes and some of their labels.
*/
interface NodeLabelClient
{
/**
* Setup the client for progressing using the supplied progressor. Called by index implementation.
* @param progressor the progressor
* @param providesLabels true if the progression can provide label information
* @param label the label to scan for
*/
void scan( IndexProgressor progressor, boolean providesLabels, int label );
void unionScan( IndexProgressor progressor, boolean providesLabels, int... labels );
void intersectionScan( IndexProgressor progressor, boolean providesLabels, int... labels );
/**
* Accept the node id and (some) labels of a candidate index entry. Return true if the entry
* is accepted, false otherwise.
* @param reference the node id of the candidate index entry
* @param labels some labels of the candidate index entry
* @return true if the entry is accepted, false otherwise
*/
boolean acceptNode( long reference, LabelSet labels );
}
/**
* Client which accepts graph entities (nodes and relationships) and a fuzzy score.
*/
interface ExplicitClient
{
/**
* Setup the client for progressing using the supplied progressor. Called by index implementation.
* @param progressor the progressor
* @param expectedSize expected number of entries this progressor will feed the client.
*/
void initialize( IndexProgressor progressor, int expectedSize );
/**
* Accept the entity id and a score. Return true if the entry is accepted, false otherwise
* @param reference the node id of the candidate index entry
* @param score score of the candidate index entry
* @return true if the entry is accepted, false otherwise
*/
boolean acceptEntity( long reference, float score );
}
IndexProgressor EMPTY = new IndexProgressor()
{
@Override
public boolean next()
{
return false;
}
@Override
public void close()
{ // no-op
}
};
}