/*  Copyright (C) 2010 Joshua Judson Rosen <rozzin@geekspace.com>.

    This program is free software: you can redistribute it and/or
    modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; see the file COPYING. If not, see
    <http://www.gnu.org/licenses/> or write to:

        The Free Software Foundation, inc.
        51 Franklin Street, Fifth Floor
        Boston, MA 02110-1301
        USA
*/

#ifndef VIRAND_GENERATOR_H
#define VIRAND_GENERATOR_H

typedef struct _VirandGenerator VirandGenerator;
typedef struct _VirandGeneratorClass VirandGeneratorClass;

VirandGenerator *virand_generator_new (gpointer item0, ...);

/* Share state with another generator: */
void virand_generator_share_state (VirandGenerator *self,
                                   VirandGenerator *other);

/* Get a pointer to the internal state--for seeding,  etc.: */
GRand *virand_generator_state (VirandGenerator *generator);

/* Select one of the generator's items: */
gpointer virand_generate_discrete (VirandGenerator *generator);

/* Add or update an item with a given weight: */
void virand_generator_set_weight (VirandGenerator *generator,
                                  gpointer item, int weight);
/* Add a series of items with given weights (followed by a NULL sentinel): */
void virand_generator_set_weights (VirandGenerator *generator,
                                   ...);


int virand_generator_remove (VirandGenerator *generator, gpointer item);
/* ^returns the weight of the removed item */


#define VIRAND_TYPE_GENERATOR            (virand_generator_get_type ())
#define VIRAND_GENERATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRAND_TYPE_GENERATOR, VirandGenerator))
#define VIRAND_IS_GENERATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRAND_TYPE_GENERATOR))

#define VIRAND_GENERATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), VIRAND_TYPE_GENERATOR, VirandGeneratorClass))
#define VIRAND_IS_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass, VIRAND_TYPE_GENERATOR)))

#define VIRAND_GENERATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRAND_TYPE_GENERATOR, VirandGeneratorClass))


GType virand_generator_get_type (void);

#endif
