~ubuntu-branches/ubuntu/natty/freecell-solver/natty

« back to all changes in this revision

Viewing changes to pqueue.c

  • Committer: Bazaar Package Importer
  • Author(s): RISKO Gergely
  • Date: 2009-03-15 23:42:21 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090315234221-sx95hxyfyfgi0pja
Tags: 2.16.0-1
* Imported Upstream version 2.16.0 (closes: #518440)
* cmake is the new buildsystem

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
   entry in the pqueue depending on whether it is ascending or descending respectively. Finally the bool32 tells you whether
33
33
   the list is sorted ascending or descending... */
34
34
 
35
 
void freecell_solver_PQueueInitialise(
 
35
void fc_solve_PQueueInitialise(
36
36
    PQUEUE *pq,
37
37
    int32 MaxElements
38
38
    )
53
53
   returns TRUE if succesful, FALSE if fails. (You fail by filling the pqueue.)
54
54
   PGetRating is a function which returns the rating of the item you're adding for sorting purposes */
55
55
 
56
 
int freecell_solver_PQueuePush( PQUEUE *pq, void *item, pq_rating_t r)
 
56
int fc_solve_PQueuePush(
 
57
        PQUEUE *pq,
 
58
        fcs_state_t * key,
 
59
        fcs_state_extra_info_t * val, 
 
60
        pq_rating_t r
 
61
        )
57
62
{
58
63
    uint32 i;
59
64
    pq_element_t * Elements = pq->Elements;
97
102
        }
98
103
 
99
104
        /* then add the element at the space we created. */
100
 
        Elements[i].item = item;
 
105
        Elements[i].key = key;
 
106
        Elements[i].val = val;
101
107
        Elements[i].rating = r;
102
108
    }
103
109
 
110
116
#define PQueueIsEmpty(pq) ((pq)->CurrentSize == 0)
111
117
 
112
118
/* free up memory for pqueue */
113
 
void freecell_solver_PQueueFree( PQUEUE *pq )
 
119
void fc_solve_PQueueFree( PQUEUE *pq )
114
120
{
115
121
    free( pq->Elements );
116
122
}
117
123
 
118
 
/* remove the first node from the pqueue and provide a pointer to it */
 
124
/* remove the first node from the pqueue and provide a pointer to it 
 
125
 *
 
126
 * Returns 0 if found.
 
127
 * Returns 1 if not found.
 
128
 *
 
129
 * */
119
130
 
120
 
void *freecell_solver_PQueuePop( PQUEUE *pq)
 
131
int fc_solve_PQueuePop( PQUEUE *pq, fcs_state_t * * key, fcs_state_extra_info_t * * val)
121
132
{
122
133
    int32 i;
123
134
    int32 child;
129
140
 
130
141
    if( PQueueIsEmpty( pq ) )
131
142
    {
132
 
        return NULL;
 
143
        *key = NULL;
 
144
        *val = NULL;
 
145
        return 1;
133
146
    }
134
147
 
135
148
    pMaxElement = Elements[PQ_FIRST_ENTRY];
167
180
    Elements[i] = pLastElement;
168
181
    pq->CurrentSize = CurrentSize;
169
182
 
170
 
    return pMaxElement.item;
 
183
    *key = pMaxElement.key;
 
184
    *val = pMaxElement.val;
 
185
    return 0;
171
186
}
172
187
 
173
188