<commit_before><?php
	
	/*
	 *	Collection is a useful 
	 *	means of storing data and 
	 *	is tightly coupled to Ant
	 *	subpackages.
	 * 
	 *	@note The namespace of a collection
	 *	is usually the table name of a mysql
	 *	table, as this is always
	 *	unique and best describes the data
	 *	held within it.
	 * 
	 *	@package Ant
	 *	@subpackage Collection
	 *	@type Shared
	 *	@require Underscore.php
	 *	@since 0.1.0
	 */
	
	namespace Ant {
		
		// Underscore alias //
		use \__ as __;
		
		Class Collection {
			
			private $records	= array(), 
					$index		= 0,
					$namespace;
			
			/*
			 *	Instantiation of collection
			 *	
			 *	@since 0.1.0
			 */
			
			public function __construct( $arr = array(), $namespace = 'stdCollection' ){
				$this->namespace	= $namespace;
				if( is_string($arr)){
					$this->namespace	= $arr;
					return;
				}
				if( ! empty($arr ) ){
					if( !is_array($arr)){
						$arr = (array) $arr;
					}
					$this->add( $arr );
				}
				return;
			}
			
			/*
			 *	Clone magic method for 
			 *	ensuring joins and 
			 *	child collections are 
			 *	also cloned.
			 *	
			 *	@since 0.1.0
			 */
			
			function __clone(){
				
				$cloneRecords = array();
				$joins			= array();
				
				$this->each( function( $record, $i ) use ( & $cloneRecords , & $joins ){
					$cloneRecords[$i] = $record->toArrayShallow();
					foreach( $record->getJoins() as $join ){
						$joins[$i][] = clone $join;
					}
				});
				
				$this->clear();
				$this->createRecords( $cloneRecords );
				
				if( count($joins) > 0 ){
					$this->each( function( $record, $i ) use( $joins ){
						if( $joins[$i] ){
							foreach( $joins[$i] as $join ){
								$record->join( $join );
							}
						}
					});
				};
			}
			
			/*
			 *	Create records based on
			 *	data 
			 *	
			 *	@since 0.1.0
			 */
			
			private function createRecords( $data ){
				foreach( $data as $each ){
					$this->records[ $this->index ] = new CollectionRecord( $this->index, $each, $this );
					$this->index++;
				}
			}
			
			/*
			 *	Get the current number
			 *	of records in the collection
			 *	
			 *	@since 0.1.0
			 *	@return int The record total
			 */
			
			public function length(){
				return $this->index;
			}
			
			/*
			 *	Get the first record
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function first(){
				return __ :: first( $this->records );
			}
			
			/*
			 *	Get the last record
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function last(){
				return __ :: last( $this->records );
			}

			/*
			 *	Get a specific record
			 *	based on index
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function at( $index ){
				return $this->records[ $index ];
			}
			
			/*
			 *	Loop through the records
			 *	executing a Closure
			 *	
			 *	@since 0.1.0
			 */
			
			public function each( $fn ){
				return __ :: each( $this->records, $fn );
			}
			
			/*
			 *	Search within the collection
			 *	for a value
			 *	
			 *	@since 0.1.0
			 *	@return Collection 
			 *	A Collection containing results
			 */
			
			public function find( $search ){
				$rec = array();
				$this->each( function( $record ) use( $search, & $rec ){
					$toArray	= $record->toArray();
					$found		= 0;
					foreach( $search as $k => $e ){
						if( $toArray[$k] == $e ){
							$found++;
						}
					}
					if( $found == count($search)){
						$rec[] = $toArray;
					}
				});
				
				return new Collection( $rec );
			}
			
			/*
			 *	Convert the collection to 
			 *	an object
			 *	
			 *	@since 0.1.0
			 *	@return stdClass
			 */
			
			public function toObject( $x = null ){
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use( & $data ){
					$data[ $i ] = $record->toObject();
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Convert the collection to 
			 *	an array
			 *	
			 *	@since 0.1.0
			 *	@return array
			 */
			
			public function toArray( $x = null ){
				
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use ( & $data ){
					$data[ $i ] = $record->toArray();
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Convert the collection to 
			 *	a shallow array
			 *	
			 *	@since 0.1.0
			 *	@return array
			 */
			
			public function toArrayShallow( $x = null ){
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use ( & $data ){
					$data[ $i ] = $record->toArray( true );
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Get the namespace of 
			 *	the collection
			 *	
			 *	@since 0.1.0
			 *	@return string The namespace
			 */
			
			public function getNamespace(){
				return $this->namespace;
			}
			
			/*
			 *	Join another collection
			 *	to a record. If the index
			 *	is not specified, the
			 *	collection is joined to 
			 *	every single record.
			 *	
			 *	@since 0.1.0
			 *	@return object The object for chaining
			 */
			
			public function join( Collection $col, $key = '_id' , $index = null ){
				// Join to every record //
				$col->setPrimaryKey( $key );
				if( is_null($index)){
					$this->each( function( $record ) use( $col ){
						$record->join( clone $col );
					});<commit_msg>Modifications to collection for primaryKey<commit_after><?php
	
	/*
	 *	Collection is a useful 
	 *	means of storing data and 
	 *	is tightly coupled to Ant
	 *	subpackages.
	 * 
	 *	@note The namespace of a collection
	 *	is usually the table name of a mysql
	 *	table, as this is always
	 *	unique and best describes the data
	 *	held within it.
	 * 
	 *	@package Ant
	 *	@subpackage Collection
	 *	@type Shared
	 *	@require Underscore.php
	 *	@since 0.1.0
	 */
	
	namespace Ant {
		
		// Underscore alias //
		use \__ as __;
		
		Class Collection {
			
			private $records	= array(), 
					$index		= 0,
					$primaryKey,
					$namespace;
			
			/*
			 *	Instantiation of collection
			 *	
			 *	@since 0.1.0
			 */
			
			public function __construct( $arr = array(), $namespace = 'stdCollection' ){
				$this->namespace	= $namespace;
				if( is_string($arr)){
					$this->namespace	= $arr;
					return;
				}
				if( ! empty($arr ) ){
					if( !is_array($arr)){
						$arr = (array) $arr;
					}
					$this->add( $arr );
				}
				return;
			}
			
			/*
			 *	Clone magic method for 
			 *	ensuring joins and 
			 *	child collections are 
			 *	also cloned.
			 *	
			 *	@since 0.1.0
			 */
			
			function __clone(){
				
				$cloneRecords = array();
				$joins			= array();
				
				$this->each( function( $record, $i ) use ( & $cloneRecords , & $joins ){
					$cloneRecords[$i] = $record->toArrayShallow();
					foreach( $record->getJoins() as $join ){
						$joins[$i][] = clone $join;
					}
				});
				
				$this->clear();
				$this->createRecords( $cloneRecords );
				
				if( count($joins) > 0 ){
					$this->each( function( $record, $i ) use( $joins ){
						if( $joins[$i] ){
							foreach( $joins[$i] as $join ){
								$record->join( $join );
							}
						}
					});
				};
			}
			
			/*
			 *	Create records based on
			 *	data 
			 *	
			 *	@since 0.1.0
			 */
			
			private function createRecords( $data ){
				foreach( $data as $each ){
					$this->records[ $this->index ] = new CollectionRecord( $this->index, $each, $this );
					$this->index++;
				}
			}
			
			/*
			 *	Get the current number
			 *	of records in the collection
			 *	
			 *	@since 0.1.0
			 *	@return int The record total
			 */
			
			public function length(){
				return $this->index;
			}
			
			/*
			 *	Get the first record
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function first(){
				return __ :: first( $this->records );
			}
			
			/*
			 *	Get the last record
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function last(){
				return __ :: last( $this->records );
			}

			/*
			 *	Get a specific record
			 *	based on index
			 *	
			 *	@since 0.1.0
			 *	@return CollectionRecord
			 */
			
			public function at( $index ){
				return $this->records[ $index ];
			}
			
			/*
			 *	Loop through the records
			 *	executing a Closure
			 *	
			 *	@since 0.1.0
			 */
			
			public function each( $fn ){
				return __ :: each( $this->records, $fn );
			}
			
			/*
			 *	Search within the collection
			 *	for a value
			 *	
			 *	@since 0.1.0
			 *	@return Collection 
			 *	A Collection containing results
			 */
			
			public function find( $search ){
				$rec = array();
				$this->each( function( $record ) use( $search, & $rec ){
					$toArray	= $record->toArray();
					$found		= 0;
					foreach( $search as $k => $e ){
						if( $toArray[$k] == $e ){
							$found++;
						}
					}
					if( $found == count($search)){
						$rec[] = $toArray;
					}
				});
				
				return new Collection( $rec );
			}
			
			/*
			 *	Convert the collection to 
			 *	an object
			 *	
			 *	@since 0.1.0
			 *	@return stdClass
			 */
			
			public function toObject( $x = null ){
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use( & $data ){
					$data[ $i ] = $record->toObject();
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Convert the collection to 
			 *	an array
			 *	
			 *	@since 0.1.0
			 *	@return array
			 */
			
			public function toArray( $x = null ){
				
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use ( & $data ){
					$data[ $i ] = $record->toArray();
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Convert the collection to 
			 *	a shallow array
			 *	
			 *	@since 0.1.0
			 *	@return array
			 */
			
			public function toArrayShallow( $x = null ){
				$data = array();
				__ :: each( $this->records, function( $record, $i ) use ( & $data ){
					$data[ $i ] = $record->toArray( true );
				});
				if( is_numeric($x) ){
					return $data[ $x ];
				}
				return $data;
			}
			
			/*
			 *	Get the namespace of 
			 *	the collection
			 *	
			 *	@since 0.1.0
			 *	@return string The namespace
			 */
			
			public function getNamespace(){
				return $this->namespace;
			}
			
			/*
			 *	Join another collection
			 *	to a record. If the index
			 *	is not specified, the
			 *	collection is joined to 
			 *	every single record.
			 *	
			 *	@since 0.1.0
			 *	@return object The object for chaining
			 */
			
			public function join( Collection $col, $index = null ){
				
				// Join to every record //
				if( is_null($index) ){
					$this->each( function( $record ) use( $col ){
						$record->join( clone $col );
					});
{'fraction_non_alphanumeric': 0.1522523355841273, 'fraction_numerical': 0.008879844602719452, 'mean_word_length': 1.7758664955070604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6705002', 'n_tokens_mistral': 5185, 'n_tokens_neox': 3545, 'n_words': 967}