@@ -64,8 +64,8 @@ use std::ops::Range;
6464/// by the delimiter provided.
6565pub struct BaseCustom < T > {
6666 primitives : Vec < T > ,
67- primitives_hash : HashMap < T , u32 > ,
68- base : u32 ,
67+ primitives_hash : HashMap < T , u8 > ,
68+ base : u64 ,
6969 delim : Option < char > ,
7070}
7171
@@ -96,20 +96,21 @@ impl BaseCustom<char> {
9696 /// for measuring the custom numeric base will only be one character long each.
9797 pub fn new ( chars : Vec < char > ) -> BaseCustom < char > {
9898 if chars. iter ( ) . count ( ) < 2 { panic ! ( "Too few numeric units! Provide two or more." ) }
99+ if chars. iter ( ) . count ( ) > 255 { panic ! ( "Too many numeric units!" ) }
99100 let mut mapped = HashMap :: with_capacity ( chars. iter ( ) . count ( ) ) ;
100101 for ( i, c) in chars. iter ( ) . enumerate ( ) {
101- mapped. insert ( c. clone ( ) , i as u32 ) ;
102+ mapped. insert ( c. clone ( ) , i as u8 ) ;
102103 }
103104 BaseCustom :: < char > {
104105 primitives : chars. clone ( ) ,
105106 primitives_hash : mapped,
106- base : chars. iter ( ) . count ( ) as u32 ,
107+ base : chars. iter ( ) . count ( ) as u64 ,
107108 delim : None ,
108109 }
109110 }
110111
111112 /// `gen` returns a String computed from the character mapping and
112- /// positional values the given u32 parameter evalutes to for your
113+ /// positional values the given u64 parameter evalutes to for your
113114 /// custom base
114115 ///
115116 /// # Example
@@ -124,7 +125,7 @@ impl BaseCustom<char> {
124125 /// ```text
125126 /// "11"
126127 /// ```
127- pub fn gen ( & self , input_val : u32 ) -> String {
128+ pub fn gen ( & self , input_val : u64 ) -> String {
128129 if input_val == 0 {
129130 return format ! ( "{}" , self . primitives[ 0 ] ) ;
130131 }
@@ -139,7 +140,7 @@ impl BaseCustom<char> {
139140 }
140141
141142
142- /// `decimal` returns a u32 value on computed from the units that form
143+ /// `decimal` returns a u64 value on computed from the units that form
143144 /// the custom base.
144145 ///
145146 /// # Example
@@ -154,12 +155,12 @@ impl BaseCustom<char> {
154155 /// ```text
155156 /// 3
156157 /// ```
157- pub fn decimal < S > ( & self , input_val : S ) -> u32
158+ pub fn decimal < S > ( & self , input_val : S ) -> u64
158159 where S : Into < String > {
159160 let input_val = input_val. into ( ) ;
160161
161162 input_val. chars ( ) . rev ( ) . enumerate ( ) . fold ( 0 , |sum, ( i, chr) |
162- sum + self . primitives_hash [ & chr] * self . base . pow ( i as u32 )
163+ sum + ( self . primitives_hash [ & chr] as u64 ) * self . base . pow ( i as u32 )
163164 )
164165 }
165166
@@ -216,23 +217,24 @@ impl BaseCustom<String> {
216217 None => chars. chars ( ) . map ( |c| format ! ( "{}" , c) ) . collect ( ) ,
217218 } ;
218219 if strings. iter ( ) . count ( ) < 2 { panic ! ( "Too few numeric units! Provide two or more." ) }
220+ if strings. iter ( ) . count ( ) > 255 { panic ! ( "Too many numeric units!" ) }
219221 let mut enumerator = strings. iter ( ) . enumerate ( ) ;
220222 loop {
221223 match enumerator. next ( ) {
222- Some ( ( i, c) ) => mapped. insert ( format ! ( "{}" , c) , i as u32 ) ,
224+ Some ( ( i, c) ) => mapped. insert ( format ! ( "{}" , c) , i as u8 ) ,
223225 None => break ,
224226 } ;
225227 }
226228 BaseCustom :: < String > {
227229 primitives : strings. iter ( ) . map ( |s| format ! ( "{}" , s) ) . collect ( ) ,
228230 primitives_hash : mapped,
229- base : strings. len ( ) as u32 ,
231+ base : strings. len ( ) as u64 ,
230232 delim : delim,
231233 }
232234 }
233235
234236 /// `gen` returns a String computed from the character mapping and
235- /// positional values the given u32 parameter evalutes to for your
237+ /// positional values the given u64 parameter evalutes to for your
236238 /// custom base
237239 ///
238240 /// # Example
@@ -247,7 +249,7 @@ impl BaseCustom<String> {
247249 /// ```text
248250 /// "11"
249251 /// ```
250- pub fn gen ( & self , input_val : u32 ) -> String {
252+ pub fn gen ( & self , input_val : u64 ) -> String {
251253 if input_val == 0 {
252254 return format ! ( "{}" , self . primitives[ 0 ] ) ;
253255 }
@@ -262,7 +264,7 @@ impl BaseCustom<String> {
262264 format ! ( "{}" , result)
263265 }
264266
265- /// `decimal` returns a u32 value on computed from the units that form
267+ /// `decimal` returns a u64 value on computed from the units that form
266268 /// the custom base.
267269 ///
268270 /// # Example
@@ -277,7 +279,7 @@ impl BaseCustom<String> {
277279 /// ```text
278280 /// 3
279281 /// ```
280- pub fn decimal < S > ( & self , input_val : S ) -> u32
282+ pub fn decimal < S > ( & self , input_val : S ) -> u64
281283 where S : Into < String > {
282284 let input_val = input_val. into ( ) ;
283285 let strings: Vec < String > = match self . delim {
@@ -286,7 +288,7 @@ impl BaseCustom<String> {
286288 } ;
287289
288290 strings. iter ( ) . rev ( ) . enumerate ( ) . fold ( 0 , |sum, ( i, chr) |
289- sum + self . primitives_hash [ & chr[ ..] ] * self . base . pow ( i as u32 )
291+ sum + ( self . primitives_hash [ & chr[ ..] ] as u64 ) * self . base . pow ( i as u32 )
290292 )
291293 }
292294
0 commit comments