Skip to content

MQ2Collections¶

MQ2Collections

Collection types for MQ -- useful for scripts to create stacks, queues, maps, lists.

Authors: TypePun

Resource Download Support Repo Quick Start

MQ2Collections is a Macroquest plugin. The plugin creates a number of collection types for scripts. Out of the box MQ supports one collection: the array. Collection types enable script writers to use data structures that more naturally pair with the algorithm they are implementing. For example, if a script writer is implementing a first-in first-out structure for casting buffs, then a queue would be an appropriate structure. On the other hand, if he or she is maintaining a set of IDs representing mobs pulled to camp, then a set or list would be the natural mechanism.

Why did I write it?¶

My motivation in writing this plugin was to expose more powerful and natural data structuring tools to script writers. With these tools, script writers will be able to express solutions that solve the problem they want to solve rather than organizing data and building data structures.

What types are available?¶

The current release makes available the following data structures: the stack, set, list, queue and map. Iterators over the set, list and map are also provided. For those familiar with the C++ Standard Template Library (STL), the types and their semantics should seem natural. If they do not, please let me know by email at: [email protected].

Limitations¶

At present, the collections hold strings. That is, if you want to store an integer, floating point value or an object, you have to first convert it (or serialize it) as a string.

Official Documentation¶

Extensive documentation and manuals can be found here: github

Top-Level Objects¶

list¶

Holds the "list" datatype

listiterator¶

Holds the "listiterator" datatype

map¶

Holds the "map" datatype

mapiterator¶

Holds the mapiterator datatype

queue¶

Holds the "queue" datatype

set¶

Holds the "set" datatype

setiterator¶

Holds the "setiterator" datatype

stack¶

Holds the "stack" datatype

DataTypes¶

list¶

A sequence of items in which it is possible to remove items from the ends or from arbitrary positions by index. The 'front' of the list is called the Head and the 'rear' the Tail. Items in the list may be indexed by ordinal position, with zero indicating the first item.

Members

int Count¶

Number of items in the list.

bool Clear¶

Removes all elements from the list. Always returns true.

bool Contains[ѕtring]¶

True if at least one instance of string is contained in the list and false otherwise.

list Splice¶

Returns a copy of the original list.

list Splice[іnt]¶

Returns a copy of the original list from the indicated position to the end of the list.

list Splice[int, int]¶

Returns a copy of the original list from the position specified by the first argument for an indicated number of elements.

int Index[ѕtring]¶

Returns the ordinal position of String in the List or -1 if String can not be found.

string Item[іnt]¶

Returns the string at the indicated position in the list.

bool Insert[int,sequence]¶

Insert a sequence of comma delimited strings into the source list before the ordinal indicated by Integer. True is returned if the sequence could be inserted and false otherwise.

bool Sort¶

Lexicographically orders the items. The source list is modified in place.

bool Reverse¶

Reorder the list in such a way that the 0'th item is swapped with the Count -1th item, the item with ordinal 1 with the Count -2th item, etc.

bool Append[sequence]¶

Insert a sequence of comma delimited strings onto the tail of the list.

int Remove[ѕtring]¶

Remove string from the input list. Return a count of how many times the item was removed.

bool Erase[іnt]¶

Remove an item from the input list by position. Return true if the item was removed or false if not.

int Replace[string,string]¶

Replaces the first string with the second string in the input list. A count of the number of times the replacement was performed is returned.

listiterator First¶

A listlterator is returned on the list where the current element under the iterator is the Head of the list if the list has elements or an empty iterator if the list is empty.

listiterator Find[ѕtring]¶

A listiterator is returned on the list where the current element under the iterator is the first item with a value equal to string if string is in the list and an empty iterator if it is not.
Remove and return the current item described at position 0 in the list. False is returned if the list is empty.

string Tail¶

Remove and return the current item described by position Count -1 in the list. False is returned if the list is empty.

int CountOf[ѕtring]¶

Return a count of the number of times string occurs in the list.

string Delimiter[ѕtring]¶

Sets the delimiter used to separate items in Insert and Append method calls. The previous delimiter is returned.

listiterator¶

A listiterator implements a forward iterator over the list type. A forward iterator is an iterator that can only be incremented. Invoking Advance on the iterator will position the iterator on the next element in the list. Elements in a list are identified by position. The positions have ordinals in the range 0 to Count -1. If there is no next element, the iterator will be positioned on the end of the list and IsEnd will be true.

Members

bool Reset¶

Positions the iterator to the start of the list. True is always returned.

bool Advance¶

The iterator is moved to the next item in the list, if one exists. True is returned if the iterator was advanced and False otherwise.

bool IsEnd¶

True if the iterator is at the end of the list.

string Value¶

Returns the element of the list under the iterator.

listiterator Clone¶

Returns a copy of the current listiterator. A copy has independent life and initially is over the same element as the source iterator.

map¶

A map is a collection of keys, each of which is associated with a value. Maps are also called dictionaries or associative arrays. The keys in a map must be unique. The values may be any arbitrary string.

Members

int Count¶

Number of items added to the map.

bool Clear¶

Removes all items from the map. True is always returned.

bool Contains[ѕtring]¶

True is returned if the item is in the map.

bool Add[string,string]¶

True is returned if the item was added to the map. If the first string, called the 'key' is already in the map, the second string, called the 'value' will be replaced.

bool Remove[ѕtring]¶

True is returned if the 'key' matching string was removed from the map.

mapiterator First¶

A mapiterator is returned on the map where the current element under the iterator is the first element in the map if the map has elements or an empty iterator if the map is empty.

mapiterator Find[ѕtring]¶

A mapiterator is returned on the map where the current element under the iterator is the item if the item is in the map and an empty iterator if it is not.

mapiterator¶

A mapiterator implements a forward iterator over the map type. A forward iterator is an iterator that can only be incremented. Invoking Advance on the iterator will position the iterator on the next element with a value lexicographically greater than the current element. If there is no next element, the iterator will be positioned on the end of the map and IsEnd will be true.

Members

bool Reset¶

Positions the iterator to the start of the map. True is always returned.

bool Advance¶

The iterator is moved to the next item in the map, if one exists. True is returned if the iterator was advanced and False otherwise.

bool IsEnd¶

True if the iterator is at the end of the map.

string Value¶

Returns the element of the map under the iterator.

string Key¶

Returns the unique key for the element of the map under the iterator.

mapiterator Clone¶

Returns a copy of the current mapiterator. A copy has independent life and initially is over the same element as the source iterator.

queue¶

A queue is a first-in, first-out data structure. Items Pushed are inserted at the rear, or 'tail' of the queue. Items removed, or Popped are taken from the 'front' of the queue.

Members

int Count¶

Number of items inserted onto the queue.

bool Push[ѕtring]¶

True if the item was pushed successfully.

string Pop¶

False is returned if IsEmpty is true.

bool IsEmpty¶

True if Count = 0, False otherwise.

string Peek¶

False is returned if IsEmpty is true.

set¶

A set is a collection of unordered unique values. In practice, the values in this set are ordered lexicographically.

Adding an item that is already in a set does not alter the set.

Members

int Count¶

Number of items added to the set.

bool Clear¶

Removes all items from the set. True is always returned.

bool Contains[ѕtring]¶

True is returned if the item is in the set.

bool Add[sequence]¶

True is returned if the item(s) were added to the set.

bool Remove[ѕtring]¶

True is returned if the item was removed from the set.

setiterator First¶

A setiterator is returned on the set where the current element under the iterator is the first element in the set if the set has elements or an empty iterator if the set is empty.

setiterator Find[ѕtring]¶

A setiterator is returned on the set where the current element under the iterator is the item if the item is in the set and an empty iterator if it is not.

setiterator¶

A setiterator implements a forward iterator over the set type. A forward iterator is an iterator that can only be incremented. Invoking Advance on the iterator will position the iterator on the next element with a value lexicographically greater than the current element. If there is no next element, the iterator will be positioned on the end of the set and IsEnd will be true.

Members

bool Reset¶

Positions the iterator to the start of the set. True is always returned.

bool Advance¶

The iterator is moved to the next item in the set, if one exists. True is returned if the iterator was advanced and False otherwise.

bool IsEnd¶

True if the iterator is at the end of the set.

string Value¶

Returns the element of the set under the iterator.

stack¶

A stack is a last-in, first-out data structure. Items inserted (Pushed) are placed on the 'top' of the queue. Items removed (Popped) are also removed from the 'top'.

Members

int Count¶

Number of items inserted onto the stack.

bool Push[ѕtring]¶

True if the item was pushed successfully.

string Pop¶

False is returned if IsEmpty is true.

bool IsEmpty¶

True if Count = 0, False otherwise.

string Peek¶

False is returned if IsEmpty is true.