[P4-dev] Help to writing functor using available C++ functions/library

Swaroop Thool swaroopthool1991 at outlook.com
Tue Feb 9 13:33:31 EST 2016

Hi Everyone,
I want to write functor for generating random values of +1/-1 to implement one of my interested algorithm in p4. So referring Antonin's post on writing own hash functions I have written something like this:struct my_hash {     uint16_t operator()(const char *buf, size_t s) const {   	return (random() & 1 ? 1 : -1);       }  };REGISTER_HASH(my_hash);  I can get access for it by writing:  field_list_calculation myhash  {    input {        hashvalue_list;                                // I dont require this , is this necessary?    }    algorithm : my_hash;     output_width : 16;}
Then calling in some action :  modify_field_with_hash_based_offset(mymetadata.val,myhash,0,1000);When I add this in my previous program which implements copy_to_cpu , I can see only 00 00 for both +1 and -1? Is this because negative value support explanation of my previous post applies here? If yes, then for both +1 and -1  it should have come as 01 01.OR I am writing above functor in wrong way? Please help.Thanks,Swaroop 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20160209/6ac636cf/attachment-0002.html>

More information about the P4-dev mailing list