Giter Site home page Giter Site logo

bag's Introduction

Bag Module

The Bag module is an implementation of a bag data structure in OCaml. It provides functions to add, remove, count elements, check if the bag is empty, convert the bag to a list, and check for unique elements.

Functionality

The Bag module provides the following functions:

empty: Returns an empty bag.

is_empty: Checks if the bag is empty.

add: Adds an element to the bag.

remove: Removes an element from the bag.

count: Counts the occurrences of an element in the bag.

tolist: Converts the bag to a list.

unique: Checks if an element appears only once in the bag.

Example

Here's an example of how to use the Bag module in an OCaml program:

open Bag

let () =
  let bag = add 1 (add 2 (add 1 empty)) in
  let updated_bag = remove 1 bag in
  let item_count = count 2 updated_bag in
  let bag_list = tolist updated_bag in
  let is_unique_item = unique 2 updated_bag in
  
  print_endline ("Updated Bag: " ^ (String.concat ", " (List.map string_of_int bag_list)));
  print_endline ("Count of 2 in the Bag: " ^ string_of_int item_count);
  print_endline ("Is 2 unique in the Bag? " ^ string_of_bool is_unique_item);

This program demonstrates adding elements to the bag, removing elements, counting occurrences, converting the bag to a list, and checking uniqueness.

License

This project is licensed under the MIT License.

bag's People

Contributors

goodship1 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.