@@ -1190,6 +1190,124 @@ where
11901190 Some ( ( n_read, vec ! [ ( clue_vertical, clue_horizontal) ] ) )
11911191 }
11921192}
1193+
1194+ pub struct OutsideCells2 < C > {
1195+ base_serializer : C ,
1196+ }
1197+
1198+ impl < C > OutsideCells2 < C > {
1199+ pub fn new ( base_serializer : C ) -> OutsideCells2 < C > {
1200+ OutsideCells2 { base_serializer }
1201+ }
1202+ }
1203+
1204+ impl < T , C > Combinator < ( Vec < T > , Vec < T > ) > for OutsideCells2 < C >
1205+ where
1206+ T : Clone + PartialEq ,
1207+ C : Combinator < T > ,
1208+ {
1209+ fn serialize ( & self , ctx : & Context , input : & [ ( Vec < T > , Vec < T > ) ] ) -> Option < ( usize , Vec < u8 > ) > {
1210+ if input. len ( ) == 0 {
1211+ return None ;
1212+ }
1213+ let height = ctx. height ?;
1214+ let width = ctx. width ?;
1215+
1216+ let input = & input[ 0 ] ;
1217+
1218+ let surrounding = [ & input. 0 [ ..] , & input. 1 [ ..] ] . concat ( ) ;
1219+ let ret = Seq :: new ( & self . base_serializer , width + height)
1220+ . serialize ( ctx, & [ surrounding] ) ?
1221+ . 1 ;
1222+
1223+ Some ( ( 1 , ret) )
1224+ }
1225+
1226+ fn deserialize ( & self , ctx : & Context , input : & [ u8 ] ) -> Option < ( usize , Vec < ( Vec < T > , Vec < T > ) > ) > {
1227+ let mut sequencer = Sequencer :: new ( input) ;
1228+
1229+ let height = ctx. height ?;
1230+ let width = ctx. width ?;
1231+
1232+ let surrounding =
1233+ sequencer. deserialize ( ctx, Seq :: new ( & self . base_serializer , width + height) ) ?;
1234+ if surrounding. len ( ) != 1 {
1235+ return None ;
1236+ }
1237+ let surrounding = surrounding. into_iter ( ) . next ( ) . unwrap ( ) ;
1238+
1239+ let clues_up = surrounding[ ..width] . to_vec ( ) ;
1240+ let clues_left = surrounding[ width..] . to_vec ( ) ;
1241+
1242+ Some ( ( sequencer. n_read ( ) , vec ! [ ( clues_up, clues_left) ] ) )
1243+ }
1244+ }
1245+
1246+ pub struct OutsideCells4 < C > {
1247+ base_serializer : C ,
1248+ }
1249+
1250+ impl < C > OutsideCells4 < C > {
1251+ pub fn new ( base_serializer : C ) -> OutsideCells4 < C > {
1252+ OutsideCells4 { base_serializer }
1253+ }
1254+ }
1255+
1256+ impl < T , C > Combinator < ( Vec < T > , Vec < T > , Vec < T > , Vec < T > ) > for OutsideCells4 < C >
1257+ where
1258+ T : Clone + PartialEq ,
1259+ C : Combinator < T > ,
1260+ {
1261+ fn serialize (
1262+ & self ,
1263+ ctx : & Context ,
1264+ input : & [ ( Vec < T > , Vec < T > , Vec < T > , Vec < T > ) ] ,
1265+ ) -> Option < ( usize , Vec < u8 > ) > {
1266+ if input. len ( ) == 0 {
1267+ return None ;
1268+ }
1269+ let height = ctx. height ?;
1270+ let width = ctx. width ?;
1271+
1272+ let input = & input[ 0 ] ;
1273+
1274+ let surrounding = [ & input. 0 [ ..] , & input. 1 [ ..] , & input. 2 [ ..] , & input. 3 [ ..] ] . concat ( ) ;
1275+ let ret = Seq :: new ( & self . base_serializer , width + height)
1276+ . serialize ( ctx, & [ surrounding] ) ?
1277+ . 1 ;
1278+
1279+ Some ( ( 1 , ret) )
1280+ }
1281+
1282+ fn deserialize (
1283+ & self ,
1284+ ctx : & Context ,
1285+ input : & [ u8 ] ,
1286+ ) -> Option < ( usize , Vec < ( Vec < T > , Vec < T > , Vec < T > , Vec < T > ) > ) > {
1287+ let mut sequencer = Sequencer :: new ( input) ;
1288+
1289+ let height = ctx. height ?;
1290+ let width = ctx. width ?;
1291+
1292+ let surrounding =
1293+ sequencer. deserialize ( ctx, Seq :: new ( & self . base_serializer , 2 * ( width + height) ) ) ?;
1294+ if surrounding. len ( ) != 1 {
1295+ return None ;
1296+ }
1297+ let surrounding = surrounding. into_iter ( ) . next ( ) . unwrap ( ) ;
1298+
1299+ let clues_up = surrounding[ ..width] . to_vec ( ) ;
1300+ let clues_down = surrounding[ width..( 2 * width) ] . to_vec ( ) ;
1301+ let clues_left = surrounding[ ( 2 * width) ..( 2 * width + height) ] . to_vec ( ) ;
1302+ let clues_right = surrounding[ ( 2 * width + height) ..] . to_vec ( ) ;
1303+
1304+ Some ( (
1305+ sequencer. n_read ( ) ,
1306+ vec ! [ ( clues_up, clues_down, clues_left, clues_right) ] ,
1307+ ) )
1308+ }
1309+ }
1310+
11931311pub struct Rooms ;
11941312
11951313impl Combinator < InnerGridEdges < Vec < Vec < bool > > > > for Rooms {
0 commit comments